Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

498
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda