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

react-robot: The machine's current state is not updated when send is triggered #192

Closed
gaofengye opened this issue Sep 14, 2022 · 4 comments
Labels
pending response Waiting on response react

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
@ehuelsmann ehuelsmann changed the title The machine's current state is not updated when send is triggered react-robot: The machine's current state is not updated when send is triggered Dec 13, 2024
@matthewp matthewp added the react label Dec 16, 2024
@matthewp
Copy link
Owner

Huh, this does sound like a bug. Going to take a look.

@matthewp
Copy link
Owner

We have a test for this example scenario here: https://github.com/matthewp/robot/blob/91ea22f2d11b4e5035f1acf3a08d6479606a683b/packages/react-robot/test/test.js and it works.

Are you perhaps expecting current to have changed immediately after calling send()?

@matthewp matthewp added the pending response Waiting on response label Dec 27, 2024
@matthewp
Copy link
Owner

matthewp commented Feb 5, 2025

Haven't heard back in a month so I'm going to close. Feel free to open a new issue if you still have the problem.

@matthewp matthewp closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending response Waiting on response react
Projects
None yet
Development

No branches or pull requests

2 participants