@xstate/react
Advanced tools
Comparing version 4.0.3 to 4.1.0
import { ActorRef, SnapshotFrom } from 'xstate'; | ||
export declare function useSelector<TActor extends ActorRef<any, any>, T>(actor: TActor, selector: (emitted: SnapshotFrom<TActor>) => T, compare?: (a: T, b: T) => boolean): T; | ||
export declare function useSelector<TActor extends ActorRef<any, any> | undefined, T>(actor: TActor, selector: (emitted: TActor extends ActorRef<any, any> ? SnapshotFrom<TActor> : undefined) => T, compare?: (a: T, b: T) => boolean): T; |
@@ -134,2 +134,5 @@ 'use strict'; | ||
const subscribe = React.useCallback(handleStoreChange => { | ||
if (!actor) { | ||
return () => {}; | ||
} | ||
const { | ||
@@ -140,3 +143,3 @@ unsubscribe | ||
}, [actor]); | ||
const boundGetSnapshot = React.useCallback(() => actor.getSnapshot(), [actor]); | ||
const boundGetSnapshot = React.useCallback(() => actor?.getSnapshot(), [actor]); | ||
const selectedSnapshot = withSelector.useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, selector, compare); | ||
@@ -143,0 +146,0 @@ return selectedSnapshot; |
@@ -137,2 +137,5 @@ 'use strict'; | ||
const subscribe = React.useCallback(handleStoreChange => { | ||
if (!actor) { | ||
return () => {}; | ||
} | ||
const { | ||
@@ -143,3 +146,3 @@ unsubscribe | ||
}, [actor]); | ||
const boundGetSnapshot = React.useCallback(() => actor.getSnapshot(), [actor]); | ||
const boundGetSnapshot = React.useCallback(() => actor?.getSnapshot(), [actor]); | ||
const selectedSnapshot = withSelector.useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, selector, compare); | ||
@@ -146,0 +149,0 @@ return selectedSnapshot; |
@@ -111,2 +111,5 @@ import * as React from 'react'; | ||
const subscribe = useCallback(handleStoreChange => { | ||
if (!actor) { | ||
return () => {}; | ||
} | ||
const { | ||
@@ -117,3 +120,3 @@ unsubscribe | ||
}, [actor]); | ||
const boundGetSnapshot = useCallback(() => actor.getSnapshot(), [actor]); | ||
const boundGetSnapshot = useCallback(() => actor?.getSnapshot(), [actor]); | ||
const selectedSnapshot = useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, selector, compare); | ||
@@ -120,0 +123,0 @@ return selectedSnapshot; |
@@ -108,2 +108,5 @@ import * as React from 'react'; | ||
const subscribe = useCallback(handleStoreChange => { | ||
if (!actor) { | ||
return () => {}; | ||
} | ||
const { | ||
@@ -114,3 +117,3 @@ unsubscribe | ||
}, [actor]); | ||
const boundGetSnapshot = useCallback(() => actor.getSnapshot(), [actor]); | ||
const boundGetSnapshot = useCallback(() => actor?.getSnapshot(), [actor]); | ||
const selectedSnapshot = useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, selector, compare); | ||
@@ -117,0 +120,0 @@ return selectedSnapshot; |
{ | ||
"name": "@xstate/react", | ||
"version": "4.0.3", | ||
"version": "4.1.0", | ||
"description": "XState tools for React", | ||
@@ -58,3 +58,3 @@ "keywords": [ | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0", | ||
"xstate": "^5.5.2" | ||
"xstate": "^5.6.2" | ||
}, | ||
@@ -80,4 +80,4 @@ "peerDependenciesMeta": { | ||
"react-dom": "^18.0.0", | ||
"xstate": "5.5.2" | ||
"xstate": "5.6.2" | ||
} | ||
} |
35132
846