Updating the game code in React 360
With the game backend all set up in the MERN application, we can update the React 360 project code we developed in Chapter 10, Developing a Web-Based VR Game, to make it render games directly from the game collection in the database.
We will use the game ID in the link that opens the React 360 application to fetch game details with the read API from within the React 360 code, and then set the data to state so the game loads details retrieved from the database instead of the static sample data we used in Chapter 10, Developing a Web-Based VR Game.
Once the code is updated, we can bundle it again and place the compiled files in the MERN application.
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...