Skip to content Skip to sidebar Skip to footer

React/redux - Why Is My Action/reducer Not Working?

Newbie here. Trying to get my Redux action to talk to my reducer and update the store. - TL;DR question further down: Context: I am only really getting issues now that i'm trying

Solution 1:

toggleLogin should just return {type: 'TOGGLE_LOGIN'}. bindActionCreators is what wraps that function in a store.dispatch call, so you are basically trying to dispatch what another dispatch returns. Also you get that 'ReferenceError: store is not defined' exception because inside your function there is no store reference.

Solution 2:

Just closing the loop on this one - looks like it was a mesh of things: i) my TOGGLE_LOGIN was indeed trying to dispatch. It should've just been returning an object. ii) i did need bindActionCreators but it would've been more appropriate with more than one action. iii) most importantly - when i was changing my TOGGLE_LOGIN to return an object... i was putting two console logs either side of it, for debugging purposes. But being a newbie/absent minded, i totally overlooked that this was effectively putting a function after a return statement. Once i took the console-logs off, i was up and running. Thanks everyone.

Post a Comment for "React/redux - Why Is My Action/reducer Not Working?"