( subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => TSnapshot, selector: (snapshot: TSnapshot) => TSelected, isEqual: (a: TSelected, b: TSelected) => boolean, )
| 63 | } |
| 64 | |
| 65 | export function useSyncExternalStoreWithSelector<TSnapshot, TSelected>( |
| 66 | subscribe: (onStoreChange: () => void) => () => void, |
| 67 | getSnapshot: () => TSnapshot, |
| 68 | selector: (snapshot: TSnapshot) => TSelected, |
| 69 | isEqual: (a: TSelected, b: TSelected) => boolean, |
| 70 | ): TSelected { |
| 71 | const selectedSnapshotRef = useRef<TSelected | undefined>() |
| 72 | |
| 73 | const getSelectedSnapshot = () => { |
| 74 | const snapshot = getSnapshot() |
| 75 | const selected = selector(snapshot) |
| 76 | |
| 77 | if ( |
| 78 | selectedSnapshotRef.current === undefined || |
| 79 | !isEqual(selectedSnapshotRef.current, selected) |
| 80 | ) { |
| 81 | selectedSnapshotRef.current = selected |
| 82 | } |
| 83 | |
| 84 | return selectedSnapshotRef.current |
| 85 | } |
| 86 | |
| 87 | return useSyncExternalStore(subscribe, getSelectedSnapshot) |
| 88 | } |
nothing calls this directly
no test coverage detected