mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 22:48:09 +01:00
basic react API
This commit is contained in:
19
frontend/src/hooks/useLocalChatHistory.js
Normal file
19
frontend/src/hooks/useLocalChatHistory.js
Normal file
@@ -0,0 +1,19 @@
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user