Adding to proxyMap or proxySet does not cause a rerender #987
Unanswered
mattmag
asked this question in
Bug report
Replies: 2 comments 4 replies
-
Is there a behavioral difference between v2.0.0 and v2.1.x? |
Beta Was this translation helpful? Give feedback.
1 reply
-
2.1.x confirmed. I've been trying a few things to get this to work. So far I've been unsuccessful. I'll update if I figure something out. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug Description
I'm not sure if I'm doing something incorrectly or trying something that is inherently unsupported, but I was surprised to find that adding to proxyMap and proxySet from any sort of callback does not seem to trigger a re-render.
This came up while handling the results of a firebase snapshot update which then added new items to a valtio proxyMap.
After investigating, I found that I could not trigger a re-render from any sort of callback, useEffect, promise, etc, but that it does work as expected when adding items to plain-old arrays.
However, you can get items added to the map to show by causing a re-render through another avenue (such as another state change)
I've linked a simple working example in codesandbox but here is the gist...
Update: After further testing it's not just asynchronously / in callbacks, I can't seem to get additions to show immediately at all, which is strange because in the docs, the To Do List Example works without issue. I've updated my codesandbox to add a "Add item immediately" button to showcase this
Reproduction Link
https://codesandbox.io/p/sandbox/sp2ptf
Beta Was this translation helpful? Give feedback.
All reactions