1.0.4 • Published 8 months ago
@awesome-cordova-library/localstorage v1.0.4
id: plugin-localstorage title: Localstorage tags:
- javascript
- typescript
- localstorage sidebar_position: 2
Localstorage
Library to use localstorage easily
Installation
npm install @awesome-cordova-library/localstorage
Vanilla
Declartion
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;
}
Usages
import LocalStorage from "@awesome-cordova-library/localstorage";
LocalStorage.setItem<string[]>("item", value);
LocalStorage.getItem<string[]>("item");
LocalStorage.removeItem("item");
LocalStorage.clear();
React
Declaration
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;
};
Usages
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 />;
}