pmndrs / valtio

🧙 Valtio makes proxy-state simple for React and Vanilla
https://valtio.dev
MIT License
9.08k stars 252 forks source link

read stale value from a "derived" proxy #617

Closed xiechao06 closed 1 year ago

xiechao06 commented 1 year ago

Summary

mix-use of useState and valtio.derive will make the component read the stale value of the derived proxy.

Link to reproduction

https://codesandbox.io/s/valtio-mix-with-state-ielduu?file=/src/App.tsx

Though this example seems harmless, this inconsistency brokes my project (in the progress of migration from redux to valtio).

but it works fine if use valtio only, https://codesandbox.io/s/valtio-not-mix-with-state-2j4ocl?file=/src/App.tsx

BTW, I've tested jotai, it also works, https://codesandbox.io/s/brave-drake-qsvvz5?file=/src/App.tsx, would you suggest using jotai instead?