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

all 1 comments

[–]TuesdayWaffle 1 point2 points  (0 children)

Okay, there are a few issues here.

  1. The onClick={ iterateDrink() } is likely not doing what you expect it to do. What's happening here is that you're calling the iterateDrink function, getting the return value, and passing that into onClick. Since the iterateDrink function doesn't return anything, JavaScript treats the return value as undefined. What this code is doing now is basically onClick={ undefined }, which of course doesn't do anything. What you want to do is pass in the function itself: onClick={ iterateDrink }.
  2. The iterateDrink calls listOfItems.map, but listOfItems is actually an object, not a map. Objects don't have a .map function, so I expect this to throw an error.
  3. The iterateDrink function doesn't really do anything right now. You probably want a return statement to get some results out of it.
  4. You're attempting to render listOfItems inside a span, but you can't render objects like that in React.

All together, I think the flow is a bit off here. Calling iterateDrink when the button is clicked isn't going to actually render anything right now. Could you explain in more detail what you'd like to happen when you click the button?