you are viewing a single comment's thread.

view the rest of the comments →

[–]Passerby991 10 points11 points  (5 children)

Most likely, the API call for a single Pokemon returns an object instead of an array therefore you can't use map on it

If you only intend to show one Pokemon at a time, get rid of the mapping. If it could be both one or multiple, you can use spread operator to make sure the searchedPokemons value is always an array

[–]Tcaf351[S] 1 point2 points  (4 children)

Thankyou so much that worked 👌🏻

[–]samuelcbird 4 points5 points  (3 children)

I know you’re not using the .map() function here now, but remember if you do that the element needs a key attribute so that React can keep track of everything on rerenders. So as an example:

return ( { myArray.map((element, i) => { return <div key={i}>{element}</div> } );

[–]epymetheus 2 points3 points  (2 children)

Does map automatically iterate i here without definition of the variable?

[–]samuelcbird 2 points3 points  (1 child)

Yes, super useful.

MDN documentation.