beekai-oss / little-state-machine

📠 React custom hook for persist state management
https://lrz5wloklm.csb.app/
MIT License
1.48k stars 53 forks source link

Does `useStateMachine` trigger re-renders when an update occurs in another component tree? #110

Closed jfreedman-eagent closed 2 years ago

jfreedman-eagent commented 2 years ago

In my app, I want to use Little State Machine to share state between two separate component trees. However, when I tried to do so, one tree failed to update after an action was dispatched in the other. Is this expected behavior?

bluebill1049 commented 2 years ago

not expected, can you share a simple codesandbox. are you using useStateMacine in another component?

jfreedman-eagent commented 2 years ago

Here's the Code Sandbox. I might not have explained it super well. I have two separate StateMachineProviders that I'd like to use the same state (in my actual app, it currently isn't feasible to combine them to use a single provider). With this setup, I expected both component trees to update at the same time, but only the tree where the update originated from was updated.

bluebill1049 commented 2 years ago

Not supporting with two providers at the moment.

jfreedman-eagent commented 2 years ago

Gotcha, just wanted to check if it was supported or not. Thanks for the quick response!

bluebill1049 commented 2 years ago

np 👍