Skip to content

Instantly share code, notes, and snippets.

@andrit
Last active October 3, 2018 13:49
Show Gist options
  • Save andrit/38013ea9ccbd48471bd0698e0d7c9881 to your computer and use it in GitHub Desktop.
Save andrit/38013ea9ccbd48471bd0698e0d7c9881 to your computer and use it in GitHub Desktop.
updateFieldValue = e => {
        this.setState({
            [e.target.name]: e.target.value
        });
    };
If nested:
onTextBoxChange = e => {
  this.setState({
    user: {
      ...this.state.user,
      [e.target.name]: e.target.value
    }
  });
};

create in parent and invoke in child:

updateFieldValue = (stateprop, value) => {
    this.setState({
      [stateprop]: value
    });
  };

//in child

 handleUpdateFieldValue = (e) => {
        let fieldName =  e.target.name; 
        let fieldValue = e.target.value;
        this.props.handleUpdateFieldValue(fieldName, fieldValue);
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment