useShallow for Valtio #871
kirankunigiri
started this conversation in
Ideas
Replies: 2 comments
-
By the way, you don't need const isSelected = useMainStore((state) => state.selectedItem === props.item.id); is fine. Don't overuse |
Beta Was this translation helpful? Give feedback.
0 replies
-
This should help: valtio/docs/how-tos/how-to-avoid-rerenders-manually.mdx Lines 29 to 46 in 9593184 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I used Zustand for several projects, and decided to give Valtio a try. I'm really enjoying it so far because of the mutable state model, but I'm missing the useShallow feature from Zustand. Being able to avoid re-renders based on whether the result of a computation changes or not was extremely handy. Is there a way to do this in Valtio?
Here is a specific example I am dealing with. I have several items, and I want them to re-render when they are clicked on and selected.
In Zustand, with useShallow, the component will only re-render if isSelected changes, instead of every time selectedItem changes.
How would I do this in Valtio?
Beta Was this translation helpful? Give feedback.
All reactions