About your reducer running twice – I think that's normal, but it shouldn't be a problem because reducers are supposed to be pure functions (with no side effects), which means running it twice should always produce the same result.
It looks like you are accidentally mutating the existing state in cartHelpers.js:
It looks like it should be comparing i.name to item.name, although obviously the code works either way since you have written your addToCart as an add / update depending on the current cart. But maybe something to refactor :)
About your reducer running twice – I think that's normal, but it shouldn't be a problem because reducers are supposed to be pure functions (with no side effects), which means running it twice should always produce the same result.
It looks like you are accidentally mutating the existing state in
cartHelpers.js
:I think that
+=
should actually just be+
and then you won't have any problems.I also noticed this line in
Store.js
which I think will actually never return true:It looks like it should be comparing
i.name
toitem.name
, although obviously the code works either way since you have written your addToCart as an add / update depending on the current cart. But maybe something to refactor :)ahh good catches, thanks for the second set of eyes! :)