class Form extends React.Component {
constructor(props) {
super(props);
this.initialState = {
name: "",
job: ""
};
this.state = this.initialState;
}
handleChange = event => {
const { name, value } = event.target;
this.setState({
[name]: value
});
};
submitForm = () => {
this.props.handleSubmit(this.state);
this.setState(this.initialState);
};
The code works okay. I just wonder what the "setState" function does In my perspective, after users submitting a form, it should empty the inititalState for further use. But after "handleChange", the initalState contains data. So why we have to reassign?