-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Redux example's store gets created twice on the server #273
Comments
@j Hi, I believe it is necessary to create the store on both getInitialProps and the constructor. getInitialProps returns a Plain javascript Object, so you need to create a store, dispatch whatever actions you need to set to your app's initial state (even async data, since getInitial Props is an async method), then return a Plain representation of this state which is passed to your component via props. In the component's constructor you retrieve the plain representation of your state via props and pass it to your store. I'm not very familiar with redux saga, do you have some code to share so I can take a look ? |
@j Hi, Have you seen redux-saga/redux-saga#255 for server side rendering. It's working just fine for me. This is how I'm doing it: You do have to be careful how you write your sagas when doing this, however. Eg. sagas that communicate with each other by dispatching actions are an issue because after you dispatch END they will cancel and no longer be able to react to each other's messages. (You can get around this by using Looking back on that it seems a bit confusing, I can write an example if you want. |
@j could you check if the above answers / solves your question? |
Hey, sorry, we moved away from next for more flexability and don't have
time to try this out. Feel free to close.
…On Thu, Dec 29, 2016 at 9:06 AM, Tim Neutkens ***@***.***> wrote:
@j <https://github.com/j> could you check if the above answers / solves
your question?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#273 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAj-Yj_weXrJgtwFjHJc0-90qLaMd_04ks5rM-ingaJpZM4K2I6P>
.
|
@MarcoThePoro do you by chance have an example of how to do this properly? I'm running into an issue where actions are getting dispatched twice :/ |
Nevermind.. got it working. For others stuck on this here is what fixed my issue:
Might be worth it to write up a recipe for using redux saga with next.js? |
@SpencerCDixon glad if you could show me the full example.. mine got stuck |
Perhaps this article helps to use Redux Saga in NextJs too. |
Is this on purpose?
getInitialProps() creates a store on the server-side, then on the constructor.
Side note:
I'm trying to use redux-saga and with this example, if you create the store again, things break.
The text was updated successfully, but these errors were encountered: