-
|
Hello. When I was checking the community comments, I saw that the recommended writing style was the following: createWithEqualityFn((state)=>{}, shallow);However, I am mentioned on the home page and in the documentation, is the following way: useStore(useShallow((state) => [state.X1,state.X2]));Which one should I use? Or are the two usages serving different purposes? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
|
Both are introduced in v4 and will stay in v5. |
Beta Was this translation helpful? Give feedback.
-
|
I created useShallowStore hook to pick any state with just array and TS support. Do you think it's good practise? @dai-shi |
Beta Was this translation helpful? Give feedback.
-
|
Do I understand correctly that for the vanilla stores made with the export function useAnnotatorStore<T>(selector: (state: AnnotatorSlices) => T): T {
const store = useContext(AnnotatorStoreContext);
if (!store) {
throw new Error('Missing `AnnotatorStoreContext.Provider` in the tree');
}
return useStore(store, selector);
}const { isNarrow } = useAnnotatorStore(useShallow((state) => ({ isNarrow: state.isNarrow }))); |
Beta Was this translation helpful? Give feedback.

Both are introduced in v4 and will stay in v5.
useShallow is newer and is basically recommended.
Basically we want to collect more feedback on them.