Skip to content

Instantly share code, notes, and snippets.

@bryanwb
Created July 9, 2021 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanwb/25583a203ab2a290b82417f3f1814cdd to your computer and use it in GitHub Desktop.
Save bryanwb/25583a203ab2a290b82417f3f1814cdd to your computer and use it in GitHub Desktop.
test useMachine in 2 components
const machine = createMachine(/* details elided */);
const Component1 = () => {
const [state, send] = useMachine(machine);
setInterval(() => send({type: 'LOGIN', password: 'foobar'}), 500
return null;
}
const Component1 = () => {
const [state, send] = useMachine(machine);
// will this have the password foobar?
return <div>{state.context.password}</div>;
}
const App = () => {
return (
<div>
<Component1 />
<Component2 />
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment