Removing an object from the array

Each VRObjectForm component can also be deleted to remove the object from the given array. GameForm will pass a removeObject method to the VRObjectForm component as a prop so the array can be updated in state when a user clicks delete on a specific VRObjectForm.

mern-vrgame/client/game/GameForm.js:

removeObject = (type, index) => event => {    const newGame = this.state.game     newGame[type].splice(index, 1)     this.setState({game: newGame}) }

The object will be removed from the array by slicing at the given index from the array of the specified array type in name.

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.