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

100
Views
using Map for an object api

i have an object format api like this:

{ success: 1,
  result:[
     {},
     {},
     {},
     {} ]
}

how can i named a map on result parameter of this object? :/

i try 2 ways for it: 1- define api to a variable like x: const [x, setX] = useState([]); then define result of api to another varibale like: const y = x.result; and then make a map on Y .

2- define api to a variable like x: const [x, setX] = useState([]); then make it array with this method: const y = Object.entries(x); and get "result" of this array like this: const result = y[1]; and make a map on result .

but after every 2 ways i see this error in console: :(

TypeError: Cannot read properties of undefined (reading 'map')

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

0

I found that you use useEffect a little bit incorrectly. You don't need return result in useEffect function. Instead it should be passed to setState function as argument:

useEffect(async () => {
    const players = await getPlayers();
    setPlayers(players);
  }, []);

as your player data fetch operation is asynchronous, you can use conditional rendering in component:

{result ? result.map(player => <Player key={player.player_key} data={player} />) : loading...}

to shure that result won't be undefined at moment of component mounting.

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!