Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get a reference to the current newSegment in state
- const { newSegment } = this.state;
- // Create a new tricks array based on the old one (just to keep it immuted)
- const tricks = [...newSegment.tricks];
- // Update the tricks array at index with a new object
- tricks[index] = {
- // If the array already had an object, use it's current values
- ...tricks[index],
- // set the name (or whatever property you want)
- name: e.target.value
- };
- // Now update the state with the updated newSegment (and tricks)
- this.setState({
- newSegment: {
- ...newSegment,
- tricks,
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement