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

The machine's current state is not updated when send is triggered #192

Open
gaofengye opened this issue Sep 14, 2022 · 1 comment
Open

Comments

@gaofengye
Copy link

gaofengye commented Sep 14, 2022

Hello Creator of react-robot,

I've been just starting to use react-robot in React 18, and I noticed that the "current" property provided from the hook "useMachine" doesn't update when I call "send('next')".
The code used is the one from the documentation:

import { useMachine } from 'react-robot';
import React from 'react';
import { createMachine, state, transition } from 'robot3';

const machine = createMachine({
one: state(
transition('next', 'two')
),
two: state()
});

function App() {
const [current, send] = useMachine(machine);

return (
<button type="button" onClick={() => send('next')}>State: ${current.name}</button>
);
}

Any idea on how to solve this? Thank you

@gaofengye
Copy link
Author

gaofengye commented Sep 23, 2022

Found a way to solve it, by replacing mounted = true by const [isMounted, setIsMounted] = useState(true); of createUseMachine function in the library robot-hooks

@matthewp matthewp transferred this issue from matthewp/react-robot Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant