I am getting this error on handleChange. I want to know what would be the issue??
const [testState, setTestState] = useState({
activeStep:0,
firstName: '',
lastName: '',
email: '',
occupation: '',
city: '',
bio: ''
});
const { activeStep } = testState;
const { firstName, lastName, email, occupation, city, bio } = testState;
const values = { firstName, lastName, email, occupation, city, bio }
const handleChange = (e) => {
const value = e.target.value;
setTestState({
...testState,
[e.target.name]: value
});
};
const handleNext = () => {
debugger
const { activeStep } = testState;
setTestState({activeStep:activeStep+1});
};
const handleBack = () => {
debugger
const { activeStep } = testState;
setTestState({activeStep:activeStep-1});
};
I am using this in material ui Stepper, like this. I want to textfield data to be there when i click next or back button. I hope you are familiar with Material Ui Stepper, it will be real help.
function getStepContent(step) {
switch (step) {
case 0:
return (
<TransportationDetail
handleNext={handleNext}
propsTransportation={propsParent.propsRateDetailsData}
exhandleChange={(e) => exhandleChange(e)}
values={values}
/>
);
case 1:
return (
<Testing 1
handleNext={handleNext}
handleBack={handleBack}
exhandleChange={(e) => exhandleChange(e)}
values={values}
/>
);
case 2:
return (
<Testing 2
handleNext={handleNext}
handleBack={handleBack}
exhandleChange={(e) => exhandleChange(e)}
values={values}
/>
);
default:
return "No data available";
}
}
Now passing as props to <Testing 1 /> Component like this:
const { values, exhandleChange } = props;
and to the textfield
<TextField
fullWidthid="outlined-size-normal"
variant="outlined"
name="firstName"
onChange={exhandleChange()}
value={values.firstName}
/>
<TextField
fullWidthid="outlined-size-normal"
variant="outlined"
name="lastName"
onChange={exhandleChange()}
value={values.lastName}
/>
e.targetis undefined. Are you passing anidperhaps instead of the event itself?e.targetonly exists ifeis the original ChangeEvent.e.targethas avalueproperty ? ..console.log(e.target)prints if you place it inhandleChangebody?onChange={exhandleChange()}toonChange={exhandleChange}you will get the event onhandleChange