I have a structure of src/resource/file.json.
1.By installing load-json and using require:
class App extends Component{
constructor(props) {
super(props);
this.state = {summaryData: [], sortBy: null};
this.sortContent = this.sortContent.bind(this);
}
componentWillMount() {
require('../resource/file.json')
.then(response => {
// Convert to JSON
return response;
})
.then(findresponse => {
// findresponse is an object
console.log(findresponse);
this.setState({summaryData: findresponse});
})
.catch(norespone => {
console.log('Im sorry but i could not fetch anything');
});
}
And appears the message : Module not found: Can't resolve '../resource/file.json' in 'C:\Xampp\htdocs\path\to\app\src\pages'
Through myJSON:
request('https://api.myjson.com/bins/{id..}').then(sumres => { if (sumres) { this.setState({summaryData: sumres}); console.log(this.state.summaryData); } });
}
But nothing appears in the console or the network tab. Cans someone propose a solution? Is it possible to load the json file without installing a local server?