DEV Community

Discussion on: Updating react nested state properties

Collapse
 
evankapantais profile image
Evan Kapantais

This is spot on. I am new to React and I tried doing it like this and it also seems to work:

  handleChange = (event) => {
    const target = event.target;

    if (target.id === "symbol") {
      this.setState({
        input: {
          symbol: target.value,
          amountHeld: this.state.input.amountHeld
        }
      });
    } else {
      this.setState({
        input: {
          symbol: this.state.input.symbol,
          amountHeld: target.value,
        }
      });
    }

    console.log(this.state);
  }
Enter fullscreen mode Exit fullscreen mode