plane/apps/app/hooks/use-local-storage.tsx
Anmol Singh Bhatia 8fb34fe1e3
feat : sidebar progress improvement (#272)
* feat: progress chart render validation

* fix: sidebar stats tab

* feat: sidebar active tab context
2023-02-13 13:14:23 +05:30

23 lines
580 B
TypeScript

import React, { useEffect, useState } from "react";
const getSavedValue = (key: any, value: any) => {
const savedValue = localStorage.getItem(key);
if (savedValue) {
return savedValue;
}
return value;
};
const useLocalStorage = (key: any, value: any) => {
const [updatedvalue, seUpdatedvalue] = useState(() => getSavedValue(key, value));
useEffect(() => {
localStorage.setItem(key, updatedvalue);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [updatedvalue]);
return [updatedvalue, seUpdatedvalue];
};
export default useLocalStorage;