Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created February 13, 2021 17:33
Show Gist options
  • Save hypeJunction/c2f487930dde717c0c76fb76f80c5af9 to your computer and use it in GitHub Desktop.
Save hypeJunction/c2f487930dde717c0c76fb76f80c5af9 to your computer and use it in GitHub Desktop.
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