1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/hooks/useStorage.ts
Roman 2279ac01ec clean up / responding to comments
Signed-off-by: Roman <ixrock@gmail.com>
2021-03-03 12:58:39 +02:00

14 lines
492 B
TypeScript

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