id | title | tags | sidebar_position | |||
---|---|---|---|---|---|---|
plugin-localstorage |
Localstorage |
|
2 |
Library to use localstorage easily
npm install @awesome-cordova-library/localstorage
class LocalStorage {
static setItem<T = any>(key: string, value: T): void;
static getItem<T = any>(key: string): T | null;
static removeItem(key: string): void;
static clear(): void;
}
import LocalStorage from "@awesome-cordova-library/localstorage";
LocalStorage.setItem<string[]>("item", value);
LocalStorage.getItem<string[]>("item");
LocalStorage.removeItem("item");
LocalStorage.clear();
const useLocalStorage: () => {
setItem: <T = any>(key: string, value: T) => void;
getItem: <T_1 = any>(key: string) => T_1 | null;
removeItem: (key: string) => void;
clear: () => void;
};
import { useEffect } from "react";
import useLocalStorage from "@awesome-cordova-library/localstorage/lib/react";
function App() {
const { setItem, getItem, removeItem, clear } = useLocalStorage();
useEffect(() => {
setItem<string[]>("item", value);
getItem<string[]>("item");
removeItem("item");
clear();
}, []);
return <div />;
}