Advertisement
JasonWhitted

Untitled

May 26th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Get a reference to the current newSegment in state
  2. const { newSegment } = this.state;
  3. // Create a new tricks array based on the old one (just to keep it immuted)
  4. const tricks = [...newSegment.tricks];
  5. // Update the tricks array at index with a new object
  6. tricks[index] = {
  7.     // If the array already had an object, use it's current values
  8.     ...tricks[index],
  9.     // set the name (or whatever property you want)
  10.     name: e.target.value
  11. };
  12. // Now update the state with the updated newSegment (and tricks)
  13. this.setState({
  14.     newSegment: {
  15.         ...newSegment,
  16.         tricks,
  17.     }
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement