I have a data.json
file in my local workspace environment.
The app is client side only.
I'm uncertain if the best (advised) way to consume such data is either via:
import data from './data.json'
// and got to town on it...
Or if I should bring that data into my React Component via a GET request (fetch, axios, etc) where I'd place it inside of a componentDidMount
async componentDidMount() {
const data = 'http://localhost:3000/data.json'
try {
const res = await fetch(data)
this.setState({res})
}
catch (error) {
console.error(error)
}
}
- What's the correct approach and best practice to go about this?
- Should CRUD requests only be used for external https end-points and not for local data like my example?
- Feel free to suggest a third approach if I missing anything here.