The key used to access the stored value.
Optional
session: boolean = falseSave data in sessionStorage (true
) or in localStorage
(false
). Default is false
.
import storeBuddy from "store-buddy";
// "foo" is the key used to access the stored value, which is created in the
// method `init`
const storage1 = storeBuddy("foo").init("bar");
// Using sessionStorage instead of localStorage is possible by specifying
// `true` in the `session` parameter
const storage2 = storeBuddy("foo", true).init("bar");
// Type safety can be enabled by providing an argument to the type parameter
type Data = {
hello: string;
world: number;
}
const storage3 = storeBuddy<Data>("foo").init({
hello: "foo",
world: 123
})
Create persistent or temporary client-side storage with a portable, type-safe wrapper around the Web Storage API.