DEV Community

Discussion on: Revisiting Redux with Context and Hooks

Collapse
 
aceabdel profile image
aceAbdel

hit there is any way to access the state tree in the actions?
like store.getState() ?

Collapse
 
visarts profile image
Brendan B

Sorry for the late reply. One way would be in the 'getRootActions' method in the StoreProvider component, to pass another parameter after dispatch, 'state', and then pass that into bindDispatchToActions to be available to any of the actions it iterates over. It's kind of clunky, but quite honestly this whole approach here is a bit heavy. I think I might, especially for a smaller app, just leave actions context out entirely, export some basic action functions from a file and just import those anywhere they're needed, passing in dispatch at point of use.