Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
How to load data from multiple json files in react

I have 10 json files in a directory inside react app. I need to search data and matching data could be any of the file. For this do i need toI load all data of each json file in the react state. If yes how to load all data of each json files in the react state.

If there any better way to do this please suggest me.

Directory structure like this:

 students/
    /level1.json
    /level2.json
    /level3.json
    /more files......
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is the sample snippet

  //Have your static jsons inside public folder, So that after compilation react able to get the static files
  const [fileData,setFileData] = useState([])
  useEffect(()=>{
    const fileList = ['level1' ,'level2' ,'level3']; //files list in public folder
    fileList.forEach(filename => {
      fetch(`./${filename}.json`).then(response => {
        return response.json() //parse json
      }).then(data => {
        setFileData(files => [...files, {[filename]:data}]); // pushing json data by key of filename
      } 
        )
    })
  },[])

fetch API will look for files like -> "http://localhost:3000/level1.json" which is actually the public directory, So if you use fetch. You need to move it under public folder.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda