Created
February 13, 2021 17:33
-
-
Save hypeJunction/c2f487930dde717c0c76fb76f80c5af9 to your computer and use it in GitHub Desktop.
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
export function Transition | |
({ | |
transitionName, | |
payload = {} | |
}) { | |
const transition = useMachineTransition(transitionName) | |
useEffect(() => { | |
transition.execute(payload) | |
}) | |
return ( | |
<> | |
{transition.loading && <p>Loading...</p>} | |
{transition.error && <p>{transition.error.message}</p>} | |
</> | |
) | |
} | |
export function State ({ | |
is, | |
children, | |
}) { | |
const { | |
state, | |
} = useMachineState() | |
const matches = Array.isArray(is) ? is : [is] | |
const isMatch = (a) => a === state | |
if (!matches.some(isMatch)) { | |
return null | |
} | |
return children | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment