Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dispatch action on client on user click? #2

Closed
ducnvhn opened this issue Mar 7, 2017 · 5 comments
Closed

How to dispatch action on client on user click? #2

ducnvhn opened this issue Mar 7, 2017 · 5 comments

Comments

@ducnvhn
Copy link

ducnvhn commented Mar 7, 2017

thank you for your awesome library.
I cant find an example of how would I dispatch action on React component on client side.?

@kirill-konshin
Copy link
Owner

Can you please provide some more information. Are you dispatching an action from getInitialState on client side or in general?

@ducnvhn
Copy link
Author

ducnvhn commented Mar 8, 2017

sorry Kirill.
I have just figured out the way to do it.

Page = withRedux(makeStore, (state) => ({
    foo: state.foo,
    custom: 'custom value',
}), actions)(Page);

where actions is the action creator. Then in the Page component, I just have to call this.props.someAction(); to dispatch store action.
Thank you for your promptly respone.

@kirill-konshin
Copy link
Owner

Wrapper works exactly the same way as connect function of react-redux. For example if you pass no mapDispatchToProps (3rd arg) then your component will simply have this.props.dispatch.

@michalsanger
Copy link

Would it be possible to call actions also in getInitialProps? All get there is the store and it's methods like dispatch

@michalsanger
Copy link

Sorry for asking, I found it:
store.dispatch(myAction())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants