Skip to content

MartinGamesCZ/zustand-hash-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zustand-hash-storage

A simple storage for zustand that uses the hash part of the URL to store the state. This is useful for sharing the state of the application with others or persisting the state between page reloads but without persisting when re-visiting page (without the hash).

Installation

npm install zustand-hash-storage

or

bun add zustand-hash-storage

Usage

import create from 'zustand';
import hashStorage from 'zustand-hash-storage';

interface State {
  count: number;
  increment: () => void;
}

const useStore = create<State>()(hashStorage((set, get) => ({
  count: 0,
  increment: () => set({ count: get().count + 1 })
}), {
  encode: true, // Whether to b64 encode the state before storing it in the hash (default: true)
  debounceInterval: 300 // The interval in milliseconds to debounce the state updates (default: 300)
}))

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published