I have to read JSON file using React.js which is stored in local drive in Mac. I tried using fetch() api but I get data undefined. Heres my code.
fetch('http://localhost:300/107k.json')
.then(req => console.log(req))
.then(data => console.log(data))
I am getting data as undefined. How will I be able to read JSON file in react.js?
Just use import
instead
import react from 'react'
//... rest of imports
import MyJson from '../path/to/json/107k.json';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With