PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 15, 2022

[FIXED] How can I store data required to render React Components?

 July 15, 2022     json, reactjs, web-deployment     No comments   

Issue

I want to implement a game where players get clues to guess a pre-determined word. I have the clues and correct answers in a JSON file. Now, I want to create a user interface using React. However, I am unable to figure out how to make my data available to the React components. What would be a good way to do this?

I created a JSON file and included it as a script in html as mentioned in this answer, but I am still not able to accessible through the React components. I am a complete beginner at web development, so I would really appreciate it if you could explain the underlying concepts.


Solution

Are you using Create React App? If so, this should be as simple as placing the JSON file with the proper syntax in the src folder. Then you can use a simple default import statement using a relative path.

import NameForImportedObject from './filename.json';



Answered By - Jorge Navarro
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing