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
@@ -12,20 +12,23 @@ A library that brings Next.js and Redux together.
12
12
>
13
13
> With that said, if you are using `app` folder, I suggest to keep Redux in client components (`"use client"`), and keep server-side state outside of Redux.
14
14
15
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
16
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
17
+
15
18
-[Motivation](#motivation)
16
19
-[Installation](#installation)
17
20
-[Usage](#usage)
18
-
-[Store](#step-1-create-a-store)
19
-
-[App](#step-2-add-store-to-your-app)
20
-
-[Pages](#step-3-add-hydration-to-pages)
21
-
-[getStaticProps](#getstaticprops)
22
-
-[getServerSideProps](#getserversideprops)
23
-
-[Page.getInitialProps](#pagegetinitialprops)
24
-
-[App.getInitialProps](#appgetinitialprops)
21
+
-[Step 1. Create a store](#step-1-create-a-store)
22
+
-[Step 2. Add store to your App](#step-2-add-store-to-your-app)
23
+
-[Step 3. Add hydration to Pages](#step-3-add-hydration-to-pages)
24
+
-[getStaticProps](#getstaticprops)
25
+
-[getServerSideProps](#getserversideprops)
26
+
-[`Page.getInitialProps`](#pagegetinitialprops)
27
+
-[`App.getInitialProps`](#appgetinitialprops)
25
28
-[State reconciliation during hydration](#state-reconciliation-during-hydration)
26
29
-[Configuration](#configuration)
27
30
-[How it works](#how-it-works)
28
-
-[Tips and Tricks](#tips-and-tricks)
31
+
-[Tips and Tricks](#tips-and-tricks)
29
32
-[Redux Toolkit](#redux-toolkit)
30
33
-[Server and Client state separation](#server-and-client-state-separation)
31
34
-[Document](#document)
@@ -34,13 +37,15 @@ A library that brings Next.js and Redux together.
34
37
-[Custom serialization and deserialization](#custom-serialization-and-deserialization)
35
38
-[Usage with Redux Saga](#usage-with-redux-saga)
36
39
-[Usage with Redux Persist](#usage-with-redux-persist)
37
-
-[Usage with Old Class Based Components](#usage-with-old-class-based-components)
40
+
-[Usage with old class-based components](#usage-with-old-class-based-components)
38
41
-[Upgrade from 8.x to 9.x](#upgrade-from-8x-to-9x)
39
42
-[Upgrade from 6.x to 7.x](#upgrade-from-6x-to-7x)
40
43
-[Upgrade from 5.x to 6.x](#upgrade-from-5x-to-6x)
41
44
-[Upgrade from 1.x to 2.x](#upgrade-from-1x-to-2x)
42
45
-[Resources](#resources)
43
46
47
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
48
+
44
49
# Motivation
45
50
46
51
Setting up Redux for static single page apps is rather simple: a single Redux store has to be created that is provided to all pages.
@@ -297,7 +302,7 @@ All pages still can have all standard data lifecycle methods, with one common pi
297
302
298
303
# State reconciliation during hydration
299
304
300
-
Each time when the user opens a page containing the `useHydration` hook, the actions performed on server will be dispatched on client as well. This may happen during initial page load and during regular page navigation. Your reducer must merge it with existing client state properly.
305
+
Each time when the user opens a page containing the `useHydration` hook, the actions performed on server will be dispatched on client as well. This may happen during initial page load and during regular page navigation. Your reducer must merge it with existing client state properly. This means "toggle" actions are not supported, each action has to analyze what's in the state and do things properly.
301
306
302
307
Best way is to use [server and client state separation](#server-and-client-state-separation).
### Using `getServerSideProps` or `getStaticProps`
589
+
####Using `getServerSideProps` or `getStaticProps`
585
590
586
591
If you don't want to opt-out of automatic pre-rendering in your Next.js app, you can manage server-called sagas on a per page basis like [the official Next.js "with Redux Saga" example](https://github.com/vercel/next.js/tree/canary/examples/with-redux-saga) does. If you do go with this option, please ensure that you await any and all sagas within any [Next.js page methods](https://nextjs.org/docs/basic-features/data-fetching). If you miss it on one of pages you'll end up with inconsistent state being sent to client.
Next.js provides [generic `getInitialProps`](https://github.com/vercel/next.js/blob/canary/packages/next/src/pages/_app.tsx#L39) which will be picked up by wrapper, so you **must not extend `App`** as you'll be opted out of Automatic Static Optimization: https://err.sh/next.js/opt-out-auto-static-optimization. Just export a regular Functional Component or extend `React.Component` as in the example above.
8.`const makeStore = (context) => {...}` is now `const makeStore = ({context, reduxWrapperMiddleware})`, you must add `reduxWrapperMiddleware` to your store
862
867
863
-
##Upgrade from 6.x to 7.x
868
+
# Upgrade from 6.x to 7.x
864
869
865
870
1. Signature of `createWrapper` has changed: instead of `createWrapper<State>` you should use `createWrapper<Store<State>>`, all types will be automatically inferred from `Store`.
5.**window.NEXT_REDUX_WRAPPER_STORE** has been removed as it was causing [issues with hot reloading](https://github.com/kirill-konshin/next-redux-wrapper/pull/324)
874
879
875
-
##Upgrade from 5.x to 6.x
880
+
# Upgrade from 5.x to 6.x
876
881
877
882
Major change in the way how things are wrapped in version 6.
878
883
@@ -888,7 +893,7 @@ Major change in the way how things are wrapped in version 6.
888
893
889
894
6.`WrappedAppProps` was renamed to `WrapperProps`.
890
895
891
-
##Upgrade from 1.x to 2.x
896
+
# Upgrade from 1.x to 2.x
892
897
893
898
If your project was using Next.js 5 and Next Redux Wrapper 1.x these instructions will help you to upgrade to 2.x.
894
899
@@ -944,9 +949,9 @@ If your project was using Next.js 5 and Next Redux Wrapper 1.x these instruction
944
949
945
950
That's it. Your project should now work the same as before.
0 commit comments