Handling the object detail change

The VR object details will update in the GameForm component state when the user changes input values in any of the VRObjectForm fields. To register this update, the GameForm passes the handleObjectChange method to the VRObjectForm component.

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

handleObjectChange = (index, type, name, val) => {    var newGame = this.state.game     newGame[type][index][name] = val     this.setState({game: newGame}) }

The handleObjectChange method updates the field value of the specific object at the index in the array with the given type, so it is reflected in the game object stored in the state in GameForm.

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.