useShallow vs selectors #2541
Unanswered
ImamJanjua
asked this question in
General
Replies: 1 comment 7 replies
-
@ImamJanjua here you go: const { someField } = useStore() // there's no optimizations here
const { someField } = useStore(state => state) // same as `useStore()`
const someField = useStore(state => state.someField) // optimized only for primitive values, so be careful when you use objects or arrays
const someField = useStore(useShallow(state => state.someField)) // optimized for any value, but be careful on nested values |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, i am bit confused. So as far as i know there are three ways to get state and actions. The first through state so
useFooStore((state) ➔ state.upateStore))
which is not not render optimized and therefore not preferred, the second one using useShallow hook and the third use the selectors. Now which method is the best for getting states and actions and why?Beta Was this translation helpful? Give feedback.
All reactions