You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wish there was a clean way to have bound action creators in getInitialProps. Right now, when passing in mapDispatchToProps to withRedux, these actions have to be created and dispatched imperatively with the store object, e.g.
staticasyncgetInitialProps({ store }){store.dispatch(plusCount());}
Unfortunately this pattern requires calling this function again inside getInitialProps, breaking the no-use-before-define rule.
staticasyncgetInitialProps({ store }){constprops=mapDispatchToProps(store.dispatch);props.plusCount();}
Given how weird that seems, and that those actions aren't often called outside of the getInitialProps method, it seems better to write a custom function that's more descriptive, and use an actions object in getInitialProps.
staticasyncgetInitialProps({ store }){constactions=getInitialActions(store);actions.plusCount();}
It'd be nice if next-redux-wrapper would pick up mapStateToProps and mapDispatchToProps and expose those props to getInitialProps.
If that seems a little awkward and potentially hazardous, exposing an actions object when mapDispatchToProps is supplied is a less ambitious solution.
The text was updated successfully, but these errors were encountered:
michaeljonathanblack
changed the title
Feature Request: Make props available in getInitialProps
Feature Request: Make mapped props available in getInitialProps
Aug 29, 2017
I'm not sure it's possible to get own props in getInitialProps. Also I think that wrapping is not really necessary, because you can dispatch actions in the way you've shown and it's cleaner and more obvious than through wrappers.
I wish there was a clean way to have bound action creators in
getInitialProps
. Right now, when passing inmapDispatchToProps
towithRedux
, these actions have to be created and dispatched imperatively with thestore
object, e.g.Preferably, that'd look something like
Unfortunately this pattern requires calling this function again inside
getInitialProps
, breaking theno-use-before-define
rule.Given how weird that seems, and that those actions aren't often called outside of the
getInitialProps
method, it seems better to write a custom function that's more descriptive, and use anactions
object ingetInitialProps
.It'd be nice if
next-redux-wrapper
would pick upmapStateToProps
andmapDispatchToProps
and expose thoseprops
togetInitialProps
.If that seems a little awkward and potentially hazardous, exposing an
actions
object whenmapDispatchToProps
is supplied is a less ambitious solution.The text was updated successfully, but these errors were encountered: