Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Fetching the game data with the load game API

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content