Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are these two methods exactly the same? #2269

Closed
liuseen-l opened this issue Dec 21, 2023 · 1 comment
Closed

Are these two methods exactly the same? #2269

liuseen-l opened this issue Dec 21, 2023 · 1 comment

Comments

@liuseen-l
Copy link

liuseen-l commented Dec 21, 2023

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?

@dbritto-dev
Copy link
Collaborator

dbritto-dev commented Dec 21, 2023

@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

@pmndrs pmndrs locked and limited conversation to collaborators Dec 22, 2023
@dai-shi dai-shi converted this issue into discussion #2271 Dec 22, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants