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

203
Vistas
What's the problem when trying to render the cards?

I'm trying to render multiple cards by pulling data from the API. But the return is an array, I don't understand why the map is not working.

const CharacterCard = () => {
  const [showModal, setShowModal] = useState(false)

  const openModal = () => {
    setShowModal(prev => !prev)
  }

  const characters = useRequestData([], `${BASE_URL}/characters`)

  const renderCard = characters.map((character) => {
    return (
      <CardContainer key={character._id} imageUrl={character.imageUrl} />
    )
  })

  return (
    <Container>
      {renderCard}
      <ModalScreen showModal={showModal} setShowModal={setShowModal} />
    </Container>
  )
}

export default CharacterCard

The hook is this

import { useEffect, useState } from "react"
import axios from "axios"

const useRequestData = (initialState, url) => {
  const [data, setData] = useState(initialState)

  useEffect(() => {
    axios.get(url)
      .then((res) => {
        setData(res.data)
      })
      .catch((err) => {
        console.log(err.data)
      })
  }, [url])

  return (data)
}

export default useRequestData

Console error:

console error image

Requisition return:

requisition return image

API: https://disneyapi.dev/docs

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you notice the axios response schema, the data entry "is the response that was provided by the server".

Disney API response includes the data entry too.

Therefore, you actually wanted to get Disney data and not the axios response, fix it to:

setData(res.data.data)

You could debugged it by logging console.log(res) or going backward in the error chain console.log(characters) should result {data: [...]}, which hints that you can't execute .map on an object.

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