I am using react material with hooks, I want to perform a reset on material form.
I have been trying to set the state but no changes are reflecting
<form className="create-account-form" autoComplete="off" onSubmit={onSubmit}>
<FormControl
error={!!errorText.first_name}
variant="outlined"
size="small"
fullWidth
>
<InputLabel>First Name</InputLabel>
<OutlinedInput
name="first_name"
className="create-account-input"
labelWidth={90}
disabled={loading}
onChange={event => handleChange("first_name", event)}
/>
</FormControl>
<Button
type="submit"
className="submit-button"
color="primary"
variant="contained"
>
Submit
</Button>
</form>;
//my state varibles
const [signUpData, setSignUpData] = useState({
first_name: ""
});
const handleChange = (field, event) => {
if (event) {
setSignUpData({
...signUpData,
[field]: event.target ? event.target.value : event
});
}
};
on submit I want to clear that data in the input field.
const onSubmit = e => {
e.preventDefault();
setSignUpData((prev) => (prev.first_name = "",));
// clearfunction()
};
make an object to reset or initial value set as
then
setSignUpData(...initial_value);
becouse you have one input used this shape orsetSignUpData(initial_value);