( subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => TSnapshot, selector: (snapshot: TSnapshot) => TSelected, isEqual: (a: TSelected, b: TSelected) => boolean, )
| 84 | * @returns The selected part of the current snapshot. |
| 85 | */ |
| 86 | export function useSyncExternalStoreWithSelector<TSnapshot, TSelected>( |
| 87 | subscribe: (onStoreChange: () => void) => () => void, |
| 88 | getSnapshot: () => TSnapshot, |
| 89 | selector: (snapshot: TSnapshot) => TSelected, |
| 90 | isEqual: (a: TSelected, b: TSelected) => boolean, |
| 91 | ): TSelected { |
| 92 | const selectedSnapshotRef = useRef<TSelected | undefined>(undefined) |
| 93 | |
| 94 | const getSelectedSnapshot = () => { |
| 95 | const snapshot = getSnapshot() |
| 96 | const selected = selector(snapshot) |
| 97 | |
| 98 | if ( |
| 99 | selectedSnapshotRef.current === undefined || |
| 100 | !isEqual(selectedSnapshotRef.current, selected) |
| 101 | ) { |
| 102 | selectedSnapshotRef.current = selected |
| 103 | } |
| 104 | |
| 105 | return selectedSnapshotRef.current |
| 106 | } |
| 107 | |
| 108 | return useSyncExternalStore(subscribe, getSelectedSnapshot) |
| 109 | } |
nothing calls this directly
no test coverage detected