April 2020
Intermediate to advanced
716 pages
18h 55m
English
We want to fetch the game data from within the React 360 code. In the React 360 project folder, we will add an api-game.js file that will contain a read fetch method that makes a call to the load game API on the server using the provided game ID. This fetch method will be defined as follows:
/MERNVR/api-game.js:
const read = (params) => { return fetch('/api/game/' + params.gameId, { method: 'GET' }).then((response) => { return response.json() }).catch((err) => console.log(err)) }export { read}
This fetch method receives the game ID in the params and makes the API call to retrieve the corresponding game from the database. It is used in componentDidMount of the React 360 entry component, which ...