mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
8fb34fe1e3
* feat: progress chart render validation * fix: sidebar stats tab * feat: sidebar active tab context
23 lines
580 B
TypeScript
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;
|