Snap with no property access should trigger render only if the full snap is accessed. #495
Closed
santiagopuentep
started this conversation in
Ideas
Replies: 2 comments 7 replies
-
Doing some tests I also see that TypeScript complains if we subscribe to only the object and not read any properties like so:
So the only way I can think of to prevent TypeScript from complaining is to add the line |
Beta Was this translation helpful? Give feedback.
2 replies
-
If I understand it correctly, it's intended design. (tbh, I had the same misconception when I first designed react-tracked api.) AFAIR, what we should make consistent (partly from the implementation perspective) is: const state = proxy({ obj: {} })
// this
const obj = useSnapshot(state.obj)
// and this
const { obj } = useSnapshot(state) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If you have a snap and you don't access any properties, the snap will trigger re-render if anything changes. I think this is a very confusing behavior and maybe it would be better if it only re-rendered if the snap itself was actually accessed, as it happens when accessing properties.
For example, to trigger re-render when there's no property access on a snap (so it re-renders if anything changes for that snap):
Wouldn't that be more clear to explain, and also more consistent? I think that the library is amazing but has too many gotchas that are hard to keep track of with a large team.
Beta Was this translation helpful? Give feedback.
All reactions