Nextjs redux, thunk and getInitialProps - how to implement
You can follow this exampleThe correct way is to pass the store to the getInitialProps
context and to the App
component so you can pass it to the Provider
.
The getInitialProps
can't access to instance of the component, this is not accessible, so you can't call this.props.fetchUsers
, but, because you are passing store to its context, you can do store.dispatch(fetchUsers())
and remove dispatch from mapDispatchToProps
.
Generally I dispatch actions in getInitialProps
and then map state to props within connect
.