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
(feat): support SSR out-of-the-box by no-op'ing in Node
- add a `nodeNoop` option that is `true` by default
- generally folks do not want to hydrate their store during SSR, so
no-op by default and require explicit opt-in to Node hydration
- see #6 for discussion
- also throw an Error if localStorage isn't supported and no
alternative storage provider has been given
(docs): add `nodeNoop` option and section on Node and SSR usage to
give more details and note possible gotchas
Copy file name to clipboardexpand all lines: README.md
+8
Original file line number
Diff line number
Diff line change
@@ -53,9 +53,17 @@ persist('some', someStore, {
53
53
-**jsonify***bool* Enables serialization as JSON (default: `true`).
54
54
-**whitelist***Array\<string\>* Only these keys will be persisted (defaults to all keys).
55
55
-**blacklist***Array\<string\>* These keys will not be persisted (defaults to all keys).
56
+
-**nodeNoop***bool* Whether this should no-op in a Node environment (default: `true`). See below for more details.
56
57
57
58
- returns a void Promise
58
59
60
+
### Node and SSR Usage
61
+
62
+
To support Server-Side Rendering (SSR) out-of-the-box, `persist` will no-op in a Node environment by default.<br>
63
+
Please note that it uses `typeof window === 'undefined'` to check. [`window` is defined in React Native](https://stackoverflow.com/questions/49911424/what-does-the-variable-window-represent-in-react-native), but may not be in test runners and other simulated environments.
64
+
65
+
If you'd like to hydrate your store in Node (vs. in the browser, which is the standard usage), set `nodeNoop` to `false` and `storage` to a supported provider for Node.
66
+
59
67
## Examples
60
68
61
69
None yet, but can take a look at [agilgur5/react-native-manga-reader-app](https://github.com/agilgur5/react-native-manga-reader-app) which uses it in production.
0 commit comments