Skip to content

How to avoid triggering tracking when I reshape snapshots in custom hook? #835

Closed Answered by jindong-zhannng
jindong-zhannng asked this question in Q&A
Discussion options

You must be logged in to vote

It's better to use useSnapshot where you actually use values, for more render optimization.

Because valtio is the implementation detail in my hook, I don't like to expose it to consumers.

Unfortunately not. It's always on or always off.

I think there should be one solution is I can get raw snapshot from snapshot(state) api for constructing my returns, then wrap them with proxy and maintain subscriptions by myself just like what useSnapshot did. But I'm not sure how complex it will be.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jindong-zhannng
Comment options

Answer selected by jindong-zhannng
@dai-shi
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants