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
Copy file name to clipboardExpand all lines: readme.md
+55-2Lines changed: 55 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -456,10 +456,10 @@ import createContext from 'zustand/context'
456
456
457
457
const { Provider, useStore } =createContext()
458
458
459
-
conststore=create(...)
459
+
constcreateStore= () =>create(...)
460
460
461
461
constApp= () => (
462
-
<Provider initialStore={store}>
462
+
<Provider initialStore={createStore()}>
463
463
...
464
464
</Provider>
465
465
)
@@ -470,6 +470,59 @@ const Component = () => {
470
470
...
471
471
}
472
472
```
473
+
<details>
474
+
<summary>createContext usage in real components</summary>
475
+
476
+
```jsx
477
+
importcreatefrom"zustand";
478
+
importcreateContextfrom"zustand/context";
479
+
480
+
// Best practice: You can move the below createContext() and createStore to a separate file(store.js) and import the Provider, useStore here/wherever you need.
0 commit comments