Iam facing issues for rehydration of zustand store with persisted data in indexeddb. #1909
Unanswered
Ashish50514561
asked this question in
Bug report
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi I am using idbkeyval for persisting data to indexeddb but everytime i refresh , the hydration is not done on the persisted data instead iam getting initial states ,please guys help me out , this is my store and i am not calling any setter function on initial render and data is being stored in indexeddb correctly.
import { Mutate, State, StoreApi, create } from "zustand";
import { persist, createJSONStorage, StateStorage } from "zustand/middleware";
import saveToLocalStorage from "./components/localStorage";
// import { db } from "./db";
import { get, set, del } from "idb-keyval";
type StoreWithPersist = Mutate<StoreApi, [["zustand/persist", unknown]]>;
const storage: StateStorage = {
getItem: async (name: string): Promise<string | null> => {
console.log(name, "has been retrieved");
console.log("here is data from storage", await get(name));
const store = await get(name);
},
setItem: async (name: string, value: string): Promise => {
console.log(name, "with value", value, "has been saved", value);
const x = (await get(name)) || null;
console.log({ x, value });
},
removeItem: async (name: string): Promise => {
console.log(name, "has been deleted");
await del(name);
},
};
const useStore = create(
persist(
(set, get) => ({
cat: "meow",
bears: "hawwww",
dataBase: false,
check: null,
_hasHydrated: false,
)
);
module.exports = useStore;
Beta Was this translation helpful? Give feedback.
All reactions