How do I use 'onTransition' when I'm using 'useMachine'? #1734
Unanswered
felippenardi
asked this question in
General
Replies: 2 comments 2 replies
-
The service is returned as a 3rd value of the tupple. You can then use |
Beta Was this translation helpful? Give feedback.
0 replies
-
const [state, send] = useMachine(machine);
useEffect(() => {
// called whenever the state changes
console.log(state);
}, [state]);
const [state, send, service] = useMachine(machine);
useEffect(() => {
const handler = (state) => { console.log(state) }
service.onTransition(handler);
return () => { service.off(handler); }
}, []); I'd strongly recommend option 1, as it is simpler. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is the way I'm starting my machine in React:
How do I hook up a log? I found that apparently I should use the
onTransition
method, but I can't find where should I get it from.Beta Was this translation helpful? Give feedback.
All reactions