Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brokeboiflex/zustand-chrome-storage

Middleware for persistent Zustand in chrome extension development
https://github.com/brokeboiflex/zustand-chrome-storage

chrome-extension crxjs zustand zustand-persist

Last synced: about 2 months ago
JSON representation

Middleware for persistent Zustand in chrome extension development

Awesome Lists containing this project

README

        

# Usage

⚠️ This package is for use within chrome extensions only ⚠️

Just import the type of storage you need and use it like you would normally.
Refer to `chrome.storage` [documentation](https://developer.chrome.com/docs/extensions/reference/api/storage) for more info about specific storage.

```js
import {
ChromeLocalStorage,
ChromeSessionStorage,
ChromeSyncStorage,
} from "zustand-chrome-storage";

const useFishLocalStore = create(
persist(
(set, get) => ({
fishes: 0,
addAFish: () => set({ fishes: get().fishes + 1 }),
}),
{
name: "food-storage", // Name of the item in chrome.storage.local
storage: createJSONStorage(() => ChromeLocalStorage),
}
)
);

const useFishSessionStore = create(
persist(
(set, get) => ({
fishes: 0,
addAFish: () => set({ fishes: get().fishes + 1 }),
}),
{
name: "food-storage", // Name of the item in chrome.storage.session
storage: createJSONStorage(() => ChromeSessionStorage),
}
)
);
const useFishSyncStore = create(
persist(
(set, get) => ({
fishes: 0,
addAFish: () => set({ fishes: get().fishes + 1 }),
}),
{
name: "food-storage", // Name of the item in chrome.storage.sync
storage: createJSONStorage(() => ChromeSyncStorage),
}
)
);
```