feat: initial release - MorkNetVizualiser v1.0
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
|
||||
export function useLocalStorage(key, defaultValue) {
|
||||
const [value, setValueState] = useState(() => {
|
||||
try {
|
||||
const stored = localStorage.getItem(key);
|
||||
return stored !== null ? JSON.parse(stored) : defaultValue;
|
||||
} catch {
|
||||
return defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
const setValue = useCallback((newVal) => {
|
||||
setValueState(prev => {
|
||||
const next = typeof newVal === 'function' ? newVal(prev) : newVal;
|
||||
try { localStorage.setItem(key, JSON.stringify(next)); } catch {}
|
||||
return next;
|
||||
});
|
||||
}, [key]);
|
||||
|
||||
return [value, setValue];
|
||||
}
|
||||
Reference in New Issue
Block a user