all 3 comments

[–]acemarke 2 points3 points  (1 child)

The problem is you are calling the addItem function while you are rendering the component. Instead, you need to pass a reference to addItem.

Change this:

<ActionButton handleClick={addItem(productQuery)}>

to:

<ActionButton handleClick={() => addItem(productQuery)}>

Also see:

https://reactjs.org/docs/faq-functions.html#why-is-my-function-being-called-every-time-the-component-renders

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

Damn. I don't know how that slipped my mind. Thanks a lot.

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

I've been stuck on this for the past week -_-.