From b3c1769051f527cb998ae5725023596a015eac9b Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Wed, 11 Sep 2024 23:32:44 -0400 Subject: [PATCH] Snapshot can be undefined --- packages/xstate-react/src/useSelector.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xstate-react/src/useSelector.ts b/packages/xstate-react/src/useSelector.ts index e8f01194a4..cbdc4cb17d 100644 --- a/packages/xstate-react/src/useSelector.ts +++ b/packages/xstate-react/src/useSelector.ts @@ -38,8 +38,8 @@ export function useSelector< const boundGetSnapshot = useCallback(() => actor?.getSnapshot(), [actor]); const boundSelector: typeof selector = useCallback( - (snapshot: Snapshot) => { - if (snapshot.status === 'error') { + (snapshot: Snapshot | undefined) => { + if (snapshot?.status === 'error') { throw snapshot.error; } return selector(snapshot as never);