jitsi-roomsv2/frontend/src/hooks/useAllChat.tsx

22 lines
551 B
TypeScript
Raw Normal View History

2023-04-10 23:28:28 +02:00
import { atom, useAtom } from 'jotai'
2023-04-08 15:58:11 +02:00
import { atomWithReducer, useReducerAtom } from 'jotai/utils'
2023-04-10 23:28:28 +02:00
import { User } from '../background/types/roomData'
2023-04-08 15:58:11 +02:00
interface ChatMessage {
content: string
sender: User
2023-04-09 10:36:52 +02:00
uuid: string
timestamp: number
2023-04-08 15:58:11 +02:00
}
2023-04-10 23:28:28 +02:00
export const allChatMessagesAtom = atomWithReducer([], (list: ChatMessage[], item: ChatMessage) =>
list.concat(item)
)
2023-04-08 15:58:11 +02:00
const useAllChat = () => {
const [chatMessages, addChatMessage] = useAtom(allChatMessagesAtom)
return { chatMesages: chatMessages, addChatMessage }
}
export default useAllChat