Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why it moves to the wrong state? #152

Closed
anatoly314 opened this issue Apr 8, 2021 · 1 comment
Closed

Why it moves to the wrong state? #152

anatoly314 opened this issue Apr 8, 2021 · 1 comment
Labels
question Further information is requested

Comments

@anatoly314
Copy link

anatoly314 commented Apr 8, 2021

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.

@matthewp
Copy link
Owner

matthewp commented Apr 8, 2021

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.

@matthewp matthewp added the question Further information is requested label Apr 8, 2021
@matthewp matthewp closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants