Spaces:
Running
Running
File size: 532 Bytes
2f49513 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import { useState } from "react";
export interface ChatEntry {
text: string;
author: "us" | "them";
}
export default function useChatHistory() {
const [entries, setEntries] = useState<ChatEntry[]>([]);
function add(text: string, author: "us" | "them") {
setEntries([...entries, { text, author }]);
}
// Shortcut for adding a message from the bot
function addThem(text: string) {
add(text, "them");
}
function addUs(text: string) {
add(text, "us");
}
return { entries, add, addThem, addUs };
}
|