Fetching the game data with the read API

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 read game API on the server using the provided game ID.

/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 is used in componentDidMount of the React 360 entry component to retrieve the game details.

This updated React 360 code is available in the branch named 'dynamic-game' on the GitHub repository at: github.com/shamahoque/MERNVR.

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.