score:2
Accepted answer
When using Create React App everything in the public
directory will be available at the root of your site, so you can move the dataset.json
file there and just fetch /dataset.json
instead.
componentDidMount() {
fetch("/dataset.json")
.then(response => response.json())
.then(json => {
console.log(json);
})
.catch(error => console.error(error));
}
Source: stackoverflow.com
Related Query
- JSON parse error when fetching a local JSON file in an enviroment created by create-react-app
- I'm getting this error when trying to read a local JSON file in Kotlin/JS+React. What is going on?
- How can I parse through local JSON file in React js?
- You need to enable javascript to run this app response when try to access local json file in react
- Why axios GET error when downloading json file from remote AWS S3 server
- read JSON file from local hard drive and parse into react app
- File not found error when trying to 'fetch' json in React App
- Fetching data from local json file
- 404 Error when trying to fetch json file from public folder in deployed create-react-app
- Fetching data from local JSON file using axios and displaying data
- fetching json data from local file
- Getting Module parse failed: Unexpected token (1:0) error when I try to import css file for a specific component in react
- Datas are not loading in datagridMUI when i used a json local file
- JSON Parse error: Unexpected identifier "Not" while fetching when I add JWT auth header
- loading json data from local file into React JS
- Syntax Error when test component with SASS file imported
- Fetch local JSON file from public folder ReactJS
- Fetching local JSON
- CORS error when connecting local React frontend to local Spring Boot middleware application
- JSON Parse error: Unrecognized token '!' - error caught by Sentry
- Unable to fetch data from local json file by axios
- Catch return json from POST with Axios when error 400 (Bad Request) occurs
- Fetching JSON returns error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 and status code 304: Not Modified
- ReactJS + D3: Parse local CSV file and passing it to state with d3-request
- How to get data from local json file using actions and axios.get() (Redux)?
- Error when trying to run a test file on React component
- JSON Error when create react app
- How can I access a local JSON file with Redux to use throughout my React app?
- How to get Image Url from local Json file in React.js
- Error when styling React components imported from index file, but not when importing directly from component file
More Query from same tag
- Installed React-Router - The URL changes, but not the view
- TailwindCSS: Using a ref to calculate width using an arbitrary value
- React dynamic routes based on json data
- React - How to get state data from a child component?
- Filtering objects based on the value of an array of objects
- React-router: ProtectedRoute authentication logic not working
- How to mock input change for filtering data based on input string using react testing library?
- Gradle Install Issue with id 'org.grails.grails-plugin'
- Editing immutable state items
- How to make a Private Route without AuthContext
- Disable save until all categories are selected
- Error: You must pass a function as a selector to useSelector
- Distinguish row clicks in Antd (ant design) table React component
- Button onClick triggered when init in React application
- Backend crashes without an error while deleting from Mongo
- Solutions to render a different header for one of my components in React
- How to render Array data in Row of react-table
- fetch call in react app doest not return body, same call works fine with postman
- How to push array of objects into state using hooks
- Why does my HTML tag remove the space before it and why doesn't line break work here?
- this.props is not a function - react form
- Infinite loop with redux-saga
- Apollo GraphQL - Associated types not included on Subscription response
- How do I change only the individual div of the onClick function to display more information?
- Passing data between Router Components in React
- createElement set HTML tag conditionally React JS
- Axios.post in React 422, Error: (Data Validation Failed.)
- Using makeStyles - useStyles() globally throws 'Invalid Hook Call' error
- (React rendering) SetInterval just keeps going faster and unpredictable
- TypeError: Cannot read properties of undefined (reading 'map'), and multiple API requests in React.js