From b946414b87ee83df2544c87727d9a4ca8c0b49a3 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 8c2944a649..2ebcbbf52f 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);