matthewp / robot

🤖 A functional, immutable Finite State Machine library

Home Page:https://thisrobot.life

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why it moves to the wrong state?

anatoly314 opened this issue · comments

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.

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.