Getting the game ID from a link

In the index.js file of the React 360 project folder, update the componentDidMount method to retrieve the game ID from the incoming URL and make a fetch call to the read game API.

/MERNVR/index.js:

componentDidMount = () => {    let gameId = Location.search.split('?id=')[1]    read({          gameId: gameId      }).then((data) => {        if (data.error) {          this.setState({error: data.error});        } else {          this.setState({            vrObjects: data.answerObjects.concat(data.wrongObjects),            game: data          });          Environment.setBackgroundImage(            {uri: data.world}          )        }    })}

Location.search gives us access to the query string in the incoming URL that loads index.html. The retrieved query string is split to get the game ID value from the id query parameter attached ...

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.