Created
March 31, 2023 16:16
-
-
Save JacobWeisenburger/eabdb5cadc947e9d35f45d6b7cf2710e to your computer and use it in GitHub Desktop.
Zustand custom persist storage template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from 'zustand' | |
import { persist, StorageValue } from 'zustand/middleware' | |
const store = createStore( | |
persist( | |
() => ( {} ), | |
{ | |
name: 'store-state', | |
storage: { | |
async getItem ( name: string ): StorageValue<unknown> { | |
return // get from storage however you want | |
}, | |
async setItem ( name: string, storageValue: StorageValue<unknown> ): Promise<void> { | |
// set in storage however you want | |
}, | |
async removeItem ( name: string ): Promise<void> { | |
// remove/delete from storage however you want | |
}, | |
}, | |
} | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment