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

148
Views
Why can't I render multiple cards using map?

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 image

requisition return image

API: https://disneyapi.dev/docs

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like the default value of the characters is undefined. So something like (characters || []).map.. will help I think. For deeper look at this you can debug useRequestData hook, as I can't see the source of that hook from you example

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!