Comparing version 5.0.0-alpha.4 to 5.0.0-alpha.5
{ | ||
"name": "zustand", | ||
"private": false, | ||
"version": "5.0.0-alpha.4", | ||
"version": "5.0.0-alpha.5", | ||
"publishConfig": { | ||
@@ -6,0 +6,0 @@ "tag": "next" |
16
react.js
@@ -38,19 +38,9 @@ 'use strict'; | ||
var import_vanilla = require("./vanilla.ts"); | ||
const { useDebugValue, useMemo, useSyncExternalStore } = import_react.default; | ||
const { useDebugValue, useSyncExternalStore } = import_react.default; | ||
const identity = (arg) => arg; | ||
const useMemoSelector = (getState, selector) => useMemo(() => { | ||
let prev; | ||
return () => { | ||
const state = getState(); | ||
if (!prev || !Object.is(prev[0], state)) { | ||
prev = [state, selector(state)]; | ||
} | ||
return prev[1]; | ||
}; | ||
}, [getState, selector]); | ||
function useStore(api, selector = identity) { | ||
const slice = useSyncExternalStore( | ||
api.subscribe, | ||
useMemoSelector(api.getState, selector), | ||
useMemoSelector(api.getInitialState, selector) | ||
() => selector(api.getState()), | ||
() => selector(api.getInitialState()) | ||
); | ||
@@ -57,0 +47,0 @@ useDebugValue(slice); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81924
1216