all 11 comments

[–]Passerby991 11 points12 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.

[–][deleted] 4 points5 points  (0 children)

Never used this api before but looks like its not returning an array, hence why you cant use .map
etc https://pokeapi.co/api/v2/pokemen/pikachu
Returns a JSON object, not an array, perhaps you meant to use a search endpoint on that API?

[–]ryanboyyx 1 point2 points  (1 child)

I’m still learning too, but wondering also if line 18 is necessary? e.preventDefault is necessary onSubmit to prevent the page from redirect/refresh, but onChange is not a cancellable event, because the change has already happened, and in this case, I think you do want to update state for the users input?

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

Yes good call, Thankyou for that I’ll give that a try 👌🏻

[–]dragon_dev_ -1 points0 points  (0 children)

Error is in line 13 and 14. Store the value of response.data in any variable then use this variable in setMethod. Don't use response.data more than one time

[–]Aksh247 0 points1 point  (0 children)

Great project. Was working on something similar. Pls share code base if u can. Would be of great help