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

188
Views
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 answers
Answer question

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 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!