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

381
Visualizações
How can I fetch multiple JSON files from one directory in React?

This is a react project. I have a folder name data inside src where there are multiples JSON files. Now I need to fetch all the JSON files from data directory but the problem is I don't know the names of the JSON files so how can I fetch all of the JSON files from data folder in React?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can also use "Promise.all" in order to await every single file as shown below. Use the method suggested by the answer above, and implement the code below as well in order to get the best result!

Promise.all([promise1, promise2, promise3]).then((values) => {
  console.log(values);
});

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to iterate through them you should create an index.ts file in your JSONs dir, and import all files in it, and export all of them as a single array that contains all the JSONs, and import it anywhere and do what you want.

index.js:

import file1 from './file1.json';
import file2 from './file2.json';

let items = [file1, file2];

export default items;

anywhere else in your app:

import items from 'URLS_DIR';
console.log(items, ` <--- items ----`); // iterate through them

Files Dir

about 4 years ago · Juan Pablo Isaza 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