mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
15 lines
527 B
TypeScript
15 lines
527 B
TypeScript
import { useState } from "react";
|
|
import { createStorage } from "../utils";
|
|
import { CreateObservableOptions } from "mobx/lib/api/observable";
|
|
|
|
export function useStorage<T>(key: string, initialValue?: T, options?: CreateObservableOptions) {
|
|
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];
|
|
}
|