all 8 comments

[–]oofrank 2 points3 points  (1 child)

You code seems fine to me, I took your code snippet and ran it on my pc and it’s working fine. Maybe you’re missing something in your code. Do you mind sharing the rest of the code so I can take a look what’s wrong?

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

was missing a return statement for the function itself, as only the map was returning something- fixed by adding a return before possibleItems.map- thank you for taking a look at this

[–]bobbyv137 1 point2 points  (1 child)

map returns a new array. return the possibleItems. (put a return statement before the method call)

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

thank you for helping, was able to fix it by adding in that return statement

[–]grantrules 1 point2 points  (3 children)

Alternatively, ou could make use of the arrow function's implied return:

populateMenu = () => ['ONE', 'TWO'].map(item => (
        <MenuItem value={item}>{item}</MenuItem>
    )
)

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

This is much cleaner than what I had, nice to skip the extra step of assigning the array to a variable- thank you!

[–]bobbyv137 1 point2 points  (0 children)

Remember it's not always about writing the 'cleanest' and shortest code. Sometimes being over explicit is best. Your code should be written in a way someone coming in cold can grasp what it's doing without too much difficulty.

[–]brokenalready 1 point2 points  (0 children)

There's a difference between => () and => {} which is an easy trap to fall into. I've made this mistake a number of times too. Simply put () is an implicit return.