Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zustand-fetching

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand-fetching - npm Package Compare versions

Comparing version 2.3.1 to 2.3.2

6

dist/examples/store/ResettableStore.js
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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc