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

115
Views
Problemas con carga de array obtenido de api y renderizarlo con .map js

tengo este problema. Estoy consultando una api en mi localhost con una aplicación en REACT.

    import React, {useEffect, useState} from "react";
import ListGroup from 'react-bootstrap/ListGroup';
import './List.scss'

const List = () => {

    const [lista, SetLista] = useState()
    
    const url = "http://127.0.0.1:8000/api/template/"
    const fetchApi = async () => {
        console.log(">>>>>>>>>>>>>>>>>>")
        const response = await fetch(url)
        console.log(">>>>>>>>>>>>>>>>>>")
        const responseJSON = await response.json()
        console.log(responseJSON[0])
        SetLista(responseJSON)
    }

    useEffect(() => {
        console.log("paso por aqui")
        fetchApi()
    }, [])

    console.log("%%%%%%%%%%")
    console.log(lista)
    console.log("%%%%%%%%%%")

    const Lista_front = () => {
        for(var x in lista){
            console.log(lista[x])
        }
    }

    return(
        <div>
            <h1>Lista de Templates</h1>
            {lista.map((li) => {
                    <div>
                        <ListGroup>
                            <ListGroup.Item action>
                                <h3>TEMPLATE: {li.tmp_name}</h3>
                            </ListGroup.Item>
                        </ListGroup>
                    </div>
                
            })}
        </div>               
    )
}

export default List;

Al momento de querer renderizar las respuestas en una lista me genera el siguiente error:

List.js:36 Uncaught TypeError: Cannot read properties of undefined (reading 'map')
    at List (List.js:36:1)
    at renderWithHooks (react-dom.development.js:16305:1)
    at mountIndeterminateComponent (react-dom.development.js:20074:1)
    at beginWork (react-dom.development.js:21587:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at beginWork$1 (react-dom.development.js:27451:1)
    at performUnitOfWork (react-dom.development.js:26557:1)
    at workLoopSync (react-dom.development.js:26466:1)

Es como que no hiciera el fetch a la api sino que de una vez el .map y por ende no hay nada en el array, alguien puede ayudarme?

about 4 years ago · Santiago Gelvez
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!