Files
SnowLuma/.pnpm-store/v11/files/35/261b69dec3f82e0aee88513dd8578b1293fb44a511f5d54e50d19acbf9878bada3f1836d68106ab78021186a25a2e41064a5a7eabdf4d53a5809324f2a1892
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

32 lines
790 B
Plaintext

import { useCallback } from "react";
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
function defaultCompare(a, b) {
return a === b;
}
function useStore(atom, selector, compare = defaultCompare) {
const subscribe = useCallback(
(handleStoreChange) => {
if (!atom) {
return () => {
};
}
const { unsubscribe } = atom.subscribe(handleStoreChange);
return unsubscribe;
},
[atom]
);
const boundGetSnapshot = useCallback(() => atom?.get(), [atom]);
const selectedSnapshot = useSyncExternalStoreWithSelector(
subscribe,
boundGetSnapshot,
boundGetSnapshot,
selector,
compare
);
return selectedSnapshot;
}
export {
useStore
};
//# sourceMappingURL=useStore.js.map