solidjs / react-solid-state

Auto tracking state management for modern React
MIT License
190 stars 5 forks source link

setting signal or store triggers UI-update of previous value #2

Closed bigmistqke closed 2 years ago

bigmistqke commented 2 years ago

setting a signal or setting a store does trigger an update of the UI, but its previous value is being rendered instead of the updated value.

example with Signal: https://codesandbox.io/s/determined-satoshi-v2xk8?file=/src/App.js example with Store: https://codesandbox.io/s/frosty-silence-syubp?file=/src/App.js

ryansolid commented 2 years ago

Thanks for the reproductions, React can be a bit to juggle this way and I wonder if I should be looking to update the approach again. In any case I will take a look when I get a chance.

ryansolid commented 2 years ago

Ok try version 0.27.1. The problem was in how nested updates were queued. I forced this on a microtask which was the easiest fix but not sure if there are other reprocussions.

bigmistqke commented 2 years ago

lovely. seems to be working great in the minimal examples. thank you! I'll implement it in my react native app and will let u know if I face any issues there.

in the meanwhile I wrote a wrapper around react's createState to mimick Solid's API for useStore: https://codesandbox.io/s/wonderful-lamport-lb7c5

probably not so performant though, react's best-practices confuse me.