Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

496
Views
Access JSON file in React without importing it

I have been importing data in the form of a JSON file into a React component:

import data from '../../public/json/data.json';

I am using the create-react-app tool, and when I run npm run build, as expected the data.json file is bundled as part of the build/static/main.js file.

What I would like is for this data.json file not to be bundled but to be referenced at run-time each time the component runs. I.e. so that it can be edited in the built app and for these edits to show in the app. I thought that by including it in my public (as opposed to src) folder this would work, but of course I am still importing it so it is bundled. Is there a way to reference it without bundling it?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use the fetch API to retrieve the JSON file asynchronously.

Check out https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch for example implementations.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!