pmndrs / zustand

🐻 Bear necessities for state management in React

Home Page:https://zustand-demo.pmnd.rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are these two methods exactly the same?

liuseen-l opened this issue · comments

const { age } = useStore()

const age = useStore((state) => state.age)

The first way feels more convenient, but the official website cases are written in the second way. do two different ways of getting a value have different implications?

@liuseen-l the first way would cause extra renders if you want to only re render a component when age changes that's why you need to use a selector, the second use a selector in order to optimize that