store.set(...) vs. useSetAtom(...)? #1405
-
If I'm only using a single store and I have access to it through
and:
From looking at the code, it looks like Are there other differences? Initially I was wondering if there were any gotchas I have to look out for when using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you are using just one external store with |
Beta Was this translation helpful? Give feedback.
-
@dai-shi as a follow up to this question, is the guidance still that it's OK to use both approaches interchangeably? In my scenario, I'm abstracting the state management and was using hooks for both getting and setting the data. I'm now wondering if it's OK to use regular functions for the setters, while keeping the custom hooks for the getters. const store = getDefaultStore();
const myDataAtom = atom<MyData>();
const useMyData = useAtomValue(myAtom);
const setMyData = (data: MyData) => store.set(myAtom, data); |
Beta Was this translation helpful? Give feedback.
If you are using just one external store with
unstable_createStore
,store.set(...)
is the same assetAtom(...)
. I don't think there are technical gotchas, but you may not want to mix them (metal model gotchas, so to say).In the future, there might be some features that would only be allowed with an internal store. (Like, experimental versioned write, which you shouldn't use as of now.)