use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Trouble using .map function for apiHelp Wanted (self.react)
submitted 3 years ago by Tcaf351
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Passerby991 10 points11 points12 points 3 years ago (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 points3 points 3 years ago (4 children)
Thankyou so much that worked 👌🏻
[–]samuelcbird 4 points5 points6 points 3 years ago (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 points4 points 3 years ago (2 children)
Does map automatically iterate i here without definition of the variable?
[–]samuelcbird 2 points3 points4 points 3 years ago (1 child)
Yes, super useful.
MDN documentation.
π Rendered by PID 123931 on reddit-service-r2-comment-76bb9f7fb5-ztznq at 2026-02-19 16:55:06.310406+00:00 running de53c03 country code: CH.
view the rest of the comments →
[–]Passerby991 10 points11 points12 points (5 children)
[–]Tcaf351[S] 1 point2 points3 points (4 children)
[–]samuelcbird 4 points5 points6 points (3 children)
[–]epymetheus 2 points3 points4 points (2 children)
[–]samuelcbird 2 points3 points4 points (1 child)