1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/hooks/useStorage.ts
Sebastian Malton b1ff34879a cleanup Lens repo with tighter linting
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
2020-07-09 17:00:23 -04:00

12 lines
485 B
TypeScript

import { useState } from "react";
import { StorageHelper, StorageHelperOptions } from "../utils";
export function useStorage<T>(key: string, initialValue?: T, options?: StorageHelperOptions): [T, (value: T) => void] {
const storage = new StorageHelper(key, initialValue, options);
const [storageValue, setStorageValue] = useState(storage.get());
const setValue = (value: T): void => {
setStorageValue(value);
storage.set(value);
};
return [storageValue, setValue];
}