22 lines
551 B
TypeScript
22 lines
551 B
TypeScript
import { atom, useAtom } from 'jotai'
|
|
import { atomWithReducer, useReducerAtom } from 'jotai/utils'
|
|
import { User } from '../background/types/roomData'
|
|
|
|
interface ChatMessage {
|
|
content: string
|
|
sender: User
|
|
uuid: string
|
|
timestamp: number
|
|
}
|
|
|
|
export const allChatMessagesAtom = atomWithReducer([], (list: ChatMessage[], item: ChatMessage) =>
|
|
list.concat(item)
|
|
)
|
|
|
|
const useAllChat = () => {
|
|
const [chatMessages, addChatMessage] = useAtom(allChatMessagesAtom)
|
|
return { chatMesages: chatMessages, addChatMessage }
|
|
}
|
|
|
|
export default useAllChat
|