Skip to content

Best Practices - Prop drill Jotai states or use useAtom? #2721

Answered by rothsandro
NayamAmarshe asked this question in Q&A
Discussion options

You must be logged in to vote

If I understand correctly, in method 2 the parent component also uses useAtom(countAtom), right?

Pedantic, method 1 is slightly better performance wise (or memory usage) because only the parent component needs to subscribe to the store and only the parent component will be rendered twice initially (see #1444). In practice, it's likely a negligible difference and you should do what feels better for your use case (e.g. use method 1 if you want make your child component reusable with different atoms / state, use method 2 if you want to use your child component in many places with always the same state).

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@dmaskasky
Comment options

Answer selected by NayamAmarshe
Comment options

You must be logged in to vote
2 replies
@NayamAmarshe
Comment options

@theogravity
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants