fixed udpate position functionnality

This commit is contained in:
Quentin Roussel
2024-03-26 14:35:10 +01:00
parent 37fc6b6fa8
commit e6563f2da5
8 changed files with 59 additions and 19 deletions

View File

@@ -0,0 +1,27 @@
"use client";
import { useEffect, useState } from "react";
export function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(initialValue);
useEffect(() => {
try {
const item = window.localStorage.getItem(key);
setStoredValue(item ? JSON.parse(item) : initialValue);
} catch (error) {
console.log(error);
}
}, []);
const setValue = value => {
try {
const valueToStore = value instanceof Function ? value(storedValue) : value;
setStoredValue(valueToStore);
window.localStorage.setItem(key, JSON.stringify(valueToStore));
} catch (error) {
console.log(error);
}
}
return [storedValue, setValue];
}