cassiozen / useStateMachine

The <1 kb state machine hook for React
MIT License
2.38k stars 47 forks source link

Async Guard functions? #89

Closed bzbetty closed 1 year ago

bzbetty commented 2 years ago

trying to use with https://react-hook-form.com/ and make a multi page wizard form.

A guard method seemed ideal to do validation between pages, however the validation function I need to call is async.

Is there any known way to have an async guard?

example const [state, send] = useStateMachine({ initial: 'name', states: { name: { on: { BACK: { }, NEXT: { target: 'location', guard: async ({ context, event }) => { //ERROR return await trigger(["field1", "field2]); }, } } }, etc