zustand-fetching
Advanced tools
Comparing version 2.3.1 to 2.3.2
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { createResettable } from "../../store/resettableStore"; | ||
const [useStore, ResetStoreProvider] = createResettable((set) => ({ | ||
import { create } from "zustand"; | ||
import { makeResettable } from "../../store/resettableStore"; | ||
const useStore = create((set) => ({ | ||
products: [], | ||
setProducts: (myProducts) => set((state) => ({ ...state, products: myProducts })), | ||
})); | ||
const ResetStoreProvider = makeResettable(useStore); | ||
export const ResettablePage = () => { | ||
@@ -8,0 +10,0 @@ const { products, setProducts } = useStore(); |
@@ -115,4 +115,5 @@ import { produce } from "immer"; | ||
if (resettable) { | ||
store.subscribe((next) => { | ||
if (next["_resettableLifeCycle"] === false) | ||
store.subscribe((next, prev) => { | ||
if (next["_resettableLifeCycle"] === false && | ||
prev["_resettableLifeCycle"] === true) | ||
setState(initialState); | ||
@@ -119,0 +120,0 @@ }); |
import { ReactNode } from "react"; | ||
import { StateCreator, StoreApi } from "zustand"; | ||
/** @deprecated use makeResettable instead */ | ||
export declare const createResettable: <STATE>(state: StateCreator<STATE, [], [], STATE>, getState?: (() => STATE) | undefined) => [import("zustand").UseBoundStore<StoreApi<STATE>>, ({ children }: { | ||
children?: ReactNode; | ||
}) => import("react/jsx-runtime").JSX.Element]; | ||
import { StoreApi } from "zustand"; | ||
export declare const makeResettable: <Store, _>(useStore: StoreApi<Store>, getState?: (() => Store) | undefined) => ({ children }: { | ||
children?: ReactNode; | ||
}) => import("react/jsx-runtime").JSX.Element; |
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; | ||
import { useEffect } from "react"; | ||
import { create } from "zustand"; | ||
/** @deprecated use makeResettable instead */ | ||
export const createResettable = (state, getState) => { | ||
const useStore = create(Object.assign(state, { _resettableLifeCycle: false })); | ||
const initialState = useStore.getState(); | ||
const ResetStoreProvider = ({ children }) => { | ||
useEffect(() => { | ||
const reset = { _resettableLifeCycle: true }; | ||
useStore.setState(reset); | ||
return () => { | ||
useStore.setState({ _resettableLifeCycle: false, ...((getState === null || getState === void 0 ? void 0 : getState()) || initialState) }, true); | ||
}; | ||
}, []); | ||
return _jsx(_Fragment, { children: children }); | ||
}; | ||
return [useStore, ResetStoreProvider]; | ||
}; | ||
export const makeResettable = (useStore, getState) => { | ||
@@ -21,0 +4,0 @@ const initialState = useStore.getState(); |
{ | ||
"name": "zustand-fetching", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Zustand fetching helpers", |
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
59198
1119