basic react API

This commit is contained in:
Steve Androulakis
2025-01-02 18:05:28 -08:00
parent 9b139ee479
commit 93ec96a406
21 changed files with 3498 additions and 24 deletions

View 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];
}