Why it moves to the wrong state?
anatoly314 opened this issue · comments
Anatoly Tarnavsky commented
https://codesandbox.io/s/material-demo-forked-bstq3?file=/demo.js
What I want: idle -> submit -> success (final state)
What I get: idle -> submit -> idle (when press success)
What I'm doing wrong?
P.S. When I use same machine with react-robot
or other hook library it works as it supposed.
Matthew Phillips commented
You're creating a new service every time the component rerenders. You need to memoize the service. This is what useMachine
in react-robot does for you.