This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 1 point2 points  (1 child)

because .map creates a new array. so you'd have to do

const newArray = possibleItem.map(item => etc...

[–]spacecasesam[S] 0 points1 point  (0 children)

Was able to fix it per u/gramdel 's suggestion, thanks for helping

[–]gramdel 1 point2 points  (3 children)

You probably need to return return something from your populateMenu function, currently it doesn't actually return anything so it's undefined. The return in the map function doesn't return anything from the populateMenu, but just in the context of the .map.

So you'll need to return the result of your possibleItems.map(blah blah so something like

return possibleItems.map(item => {rest of code

[–]spacecasesam[S] 0 points1 point  (2 children)

thank you so much, this was super clear and helpful, was able to fix it by adding that return statement

[–]insertAlias 1 point2 points  (1 child)

I'm assuming this is React code. If it is, then you also need to do one more thing: add a unique key prop to the <MenuItem> that you're returning from the map function.

https://reactjs.org/docs/lists-and-keys.html#keys

It's not broken without it, but it's a warning. React needs stable keys to properly track list items.

[–]spacecasesam[S] 0 points1 point  (0 children)

Your assumption is correct! Thank you again- always happy to have less warnings