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

196
Vistas
React, local json file won't display

I have a local json which is returning all values on console.log so I know the path is correct. However when I am trying to pull an input value of name from it, it gives me error uni.map is not a function.

What am I'm missing, any help will be fab :).

import { useState } from 'react'
import axios from 'axios'
import Uni from './Uni'

function Unis() {
    const [unis, setUnis] = useState([])
    const [query, setQuery] = useState('')

    function handleSearchQuery(e) {
        e.preventDefault()
        setQuery(e.target.value)
    }

    async function searchUnis(e) {
        e.preventDefault()
        console.log()
        var response = await axios.get(data.json)
        setUnis(response.data)
    }
    return (
        <div>
        <input value={query} onChange={handleSearchQuery} />
        <button onClick={searchUnis}>Search</button>
        <ul>
        {
            unis.map(function(i, index){
                return (
                    <li key={index}>
                        <Uni name={i.name} />
                    </li>
                )
            })
        }
        </ul>
        </div>
    )
}   
export default Unis;

data.json

{
  "data": [
    {
      "name": "xxx",
      "years": "2022"
    },
    {
      "name": "hhh",
      "years": "2021"
    }
]
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Good Luck,

You have used data.json directly without import.

var response = await axios.get(data.json)

Ans:

Step 1:

Import the data.json file in Unis file.

import Data from './data.json';

Step 2:

Use the data like below.

var response = await axios.get(Data.data);
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