- Using JSON with React
- There are a number of ways to connect JSON to your REACT app. Here are just a couple of woefully imcomplete methods
- Using a callback with fetch:
fetch('./app/test.json') // make the request for the json file .then(function(response) { // Convert to JSON return response.json(); }).then(function(obj) { // Yay, `j` is a JavaScript object console.log(obj); });
- Importing using the json-loader in webpack:
- npm --save-dev json-loader
- In your webpack.config.js file: Include the module loader for json files, targeting "/.json$/ and specifying loader "json-loader"
Created
November 2, 2016 01:22
-
-
Save JoniWeiss/b0100a9e0c5e939ffe08670207a0e0e7 to your computer and use it in GitHub Desktop.
JSON Help
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment