#React context with state machine as global state
1 messages · Page 1 of 1 (latest)
Thanks for asking here 🙂 Do you have a code sample to share?
Sure will share a sandbox shortly
@dire lava https://codesandbox.io/p/sandbox/epic-flower-xwvlgp here is the link
@vivid swan
Can you please provide more detail on what doesn't work? E.g. what is expected and what is the actual result? I'm not sure what to do here - there are two buttons
Which should I click first, and what should I expect to see?
Hmmm ok, So the expected is when you click the "click to send test event to child machine" button to see an alert when the child machine invokes this action
{ actions: { testChildAction: () => { alert("test child event works now"); console.log("test child event works now"); }, }, },
@vivid swan
But instead this is not happening because the child machine is not interpreted somehow
but if you click the first button "Click to re-render the child" you will see the alert
The key is to useSelector which keeps it up to date:
const childRef = useSelector(parentRef, s => s.children.child);
Yeah, thanks it works now
but I wonder why I have to use useSelector!