mirror of
https://github.com/siteboon/claudecodeui.git
synced 2025-12-12 10:59:37 +00:00
fix: Address coderabbitai feedback
This commit is contained in:
@@ -1,7 +1,17 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom hook to persist state in localStorage.
|
||||||
|
*
|
||||||
|
* @param {string} key The key to use for localStorage.
|
||||||
|
* @param {any} initialValue The initial value to use if nothing is in localStorage.
|
||||||
|
* @returns {[any, Function]} A tuple containing the stored value and a setter function.
|
||||||
|
*/
|
||||||
function useLocalStorage(key, initialValue) {
|
function useLocalStorage(key, initialValue) {
|
||||||
const [storedValue, setStoredValue] = useState(() => {
|
const [storedValue, setStoredValue] = useState(() => {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return initialValue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const item = window.localStorage.getItem(key);
|
const item = window.localStorage.getItem(key);
|
||||||
return item ? JSON.parse(item) : initialValue;
|
return item ? JSON.parse(item) : initialValue;
|
||||||
@@ -12,11 +22,14 @@ function useLocalStorage(key, initialValue) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const setValue = (value) => {
|
const setValue = (value) => {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const valueToStore =
|
const valueToStore =
|
||||||
value instanceof Function ? value(storedValue) : value;
|
value instanceof Function ? value(storedValue) : value;
|
||||||
setStoredValue(valueToStore);
|
|
||||||
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
||||||
|
setStoredValue(valueToStore);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user