Files
SnowLuma/.pnpm-store/v11/files/76/c4dcd5ac8b38c1af16393ab17dff325f256f2ee5c5ede6ea3a28e583f8a9b3b7d5c3818759d6a4c3b93d0ea478cc4973aa6266b53117e79e1c70747722d617
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

32 lines
885 B
Plaintext

"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("react");
const withSelector = require("use-sync-external-store/shim/with-selector");
function defaultCompare(a, b) {
return a === b;
}
function useStore(atom, selector, compare = defaultCompare) {
const subscribe = react.useCallback(
(handleStoreChange) => {
if (!atom) {
return () => {
};
}
const { unsubscribe } = atom.subscribe(handleStoreChange);
return unsubscribe;
},
[atom]
);
const boundGetSnapshot = react.useCallback(() => atom?.get(), [atom]);
const selectedSnapshot = withSelector.useSyncExternalStoreWithSelector(
subscribe,
boundGetSnapshot,
boundGetSnapshot,
selector,
compare
);
return selectedSnapshot;
}
exports.useStore = useStore;
//# sourceMappingURL=useStore.cjs.map