Skip to content

Bug: Can't handle errors thrown from state machine in React #5455

@sfc-gh-dperezalvarez

Description

@sfc-gh-dperezalvarez

XState version

XState version 5

Description

If I'm starting a state machine from React, and the state machine throws a synchronous error, I'm not able to display it.

I modified the starter StackBlitz example to throw from an action in the submit state: https://stackblitz.com/edit/github-zdh2xswa?file=src%2FApp.tsx,src%2FfeedbackMachine.ts

To repro, press "Bad", then enter some text in the form, then press "Submit".

In the Feedback component, I try to render the value of state.error, but the component never updates.

Expected result

My expectation was that the component would update, and render the error string.

Actual result

The component didn't update after the error was thrown.

Reproduction

https://stackblitz.com/edit/github-zdh2xswa?file=src%2FApp.tsx,src%2FfeedbackMachine.ts

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions