Skip to content

Commit c9a7aa0

Browse files
author
Cassio Zen
committed
Allow self-transitions
1 parent b342613 commit c9a7aa0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,11 @@ function useStateMachineImpl<Context, Events>(context: Context): UseStateMachine
190190
useEffect(() => {
191191
const exit = config.states[machine.value]?.effect?.(send, update, machine.event);
192192
return typeof exit === 'function' ? () => exit(send, update, machine.event) : undefined;
193-
// We are bypassing the linter here because we deliberately want the effects to run on explicit machine state changes.
193+
// We are bypassing the linter here because we deliberately want the effects to run:
194+
// - When the machine state changes or
195+
// - When a different event was sent (e.g. self-transition)
194196
// eslint-disable-next-line react-hooks/exhaustive-deps
195-
}, [machine.value]);
197+
}, [machine.value, machine.event]);
196198

197199
return [machine, send];
198200
};

0 commit comments

Comments
 (0)