Replies: 1 comment 5 replies
-
Do you need separate stores? Instead of using the same atom with multiple stores I would rather create separate atoms for each counter and use just one store. You can use an atom family or atoms in atoms. The random initial value can then be computed when creating the atom. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, i'm testing using jotai Provider in a situation where i have:
So i need to use the Provider for sure.
Looking at docs, I was able to use 2 distinct patterns for doing that, I did, and both are working.
So my question is: Is threre a difference between the two or they are equivalent??
Pattern 1
with
<Provider>
pattern 1 (<AtomsHydrator>
)https://codesandbox.io/p/devbox/jotai--providers-jlyts5?file=%2Fsrc%2Fcomponents%2Fviews%2Fjotai%2Freusable-store-1%2Findex.tsx
Pattern 2
with
<Provider>
pattern 2 (createStore()
)https://codesandbox.io/p/devbox/jotai--providers-jlyts5?file=%2Fsrc%2Fcomponents%2Fviews%2Fjotai%2Freusable-store-2%2Findex.tsx
Edit 1:
Added direct link to specific code of the sandbox to every pattern
Edit 2:
Added other Pattern, emerged in the conversation.
The original question has only Pattern 1 and 2.
Pattern 3
without Provider, with atom instances saved in useState
https://codesandbox.io/p/devbox/jotai--providers-jlyts5?file=%2Fsrc%2Fcomponents%2Fviews%2Fjotai%2Freusable-store-3%2Findex.tsx
Pattern 4
without Provider, with atomFamily and atom instances saved in useState
https://codesandbox.io/p/devbox/jotai--providers-jlyts5?file=%2Fsrc%2Fcomponents%2Fviews%2Fjotai%2Freusable-store-4%2Findex.tsx
Pattern 5
without Provider, with jotai-scope
https://codesandbox.io/p/devbox/jotai--providers-jlyts5?file=%2Fsrc%2Fcomponents%2Fviews%2Fjotai%2Freusable-store-5%2Findex.tsx
Beta Was this translation helpful? Give feedback.
All reactions