Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 24, 2018 20:04
Show Gist options
  • Save andrit/a6a39b28cf528917eb78b15c3fa336e3 to your computer and use it in GitHub Desktop.
Save andrit/a6a39b28cf528917eb78b15c3fa336e3 to your computer and use it in GitHub Desktop.

React component form field update of nested state for any text field in form

this.state={
user:{
  name: '',
  age: '',
  
}
}
 onTextBoxChange = e => {
    this.setState({
      user: {
        ...this.state.user,
        [e.target.name]: e.target.value
      }
    });
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment