mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 06:28:08 +01:00
20 lines
527 B
JavaScript
20 lines
527 B
JavaScript
import { useState, useEffect } from "react";
|
|
|
|
export default function useLocalChatHistory(key, initialValue) {
|
|
const [state, setState] = useState(() => {
|
|
try {
|
|
const stored = window.localStorage.getItem(key);
|
|
return stored ? JSON.parse(stored) : initialValue;
|
|
} catch (err) {
|
|
console.error("Error parsing localStorage:", err);
|
|
return initialValue;
|
|
}
|
|
});
|
|
|
|
useEffect(() => {
|
|
window.localStorage.setItem(key, JSON.stringify(state));
|
|
}, [key, state]);
|
|
|
|
return [state, setState];
|
|
}
|