Created
July 9, 2021 12:04
-
-
Save bryanwb/25583a203ab2a290b82417f3f1814cdd to your computer and use it in GitHub Desktop.
test useMachine in 2 components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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