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

zustand-cookie-storage

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand-cookie-storage

`zustand-cookie-storage` is a utility library designed to enhance the state management capabilities of Zustand by persisting state in cookies. This package enables seamless storage and retrieval of state across sessions and browser tabs using cookies as a

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
217
increased by87.07%
Maintainers
0
Weekly downloads
 
Created
Source

NPM Version License Build Status

zustand-cookie-storage is a plugin for Zustand that allows you to persist your store's state in cookies. This package makes it easy to maintain state across sessions and browser tabs.

Features

  • Persist Zustand State in Cookies: Save and load Zustand state from cookies automatically.
  • Customizable: Configure cookie attributes like expires, path, secure, and more.
  • Server-Side Rendering Friendly: Ideal for use in SSR frameworks such as Next.js.
  • Lightweight: Minimalistic design with a small footprint.

Installation

Install the package via npm or yarn:

npm install zustand-cookie-storage
# or
yarn add zustand-cookie-storage

Example

import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { cookieStorage } from "zustand-cookie-storage";

const useMainStore = create(
  persist(
    (...args) => ({
      ...locationSlice(...args),
      ...profileSlice(...args),
    }),
    {
      name: "main",
      storage: createJSONStorage(() => cookieStorage),
      partialize(state) {
        return {
          basketIds: state.basketIds
        };
      },
    }
  )
);
export default useMainStore;

An Example

Keywords

FAQs

Package last updated on 01 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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