update useLocalState to use initialValue directly as useState initialState

This commit is contained in:
Abhinav 2023-03-29 19:31:03 +05:30
parent 255769c3a9
commit c57f93802b

View file

@ -5,11 +5,13 @@ export function useLocalState<T>(
key: LS_KEYS,
initialValue?: T
): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>();
const [value, setValue] = useState<T>(initialValue);
useEffect(() => {
const { value } = getData(key) ?? {};
setValue(value ?? initialValue);
if (value) {
setValue(value);
}
}, []);
useEffect(() => {