reusable chat
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import * as api from '../service/ChatService'
|
||||
import type { AddChatMessageType } from '../type/Types'
|
||||
|
||||
export const useGetChatMessages = (refId: string) => {
|
||||
return useQuery({
|
||||
queryKey: ['chat', refId],
|
||||
queryFn: () => api.getChatMessages(refId),
|
||||
enabled: !!refId,
|
||||
})
|
||||
}
|
||||
|
||||
export const useAddChatMessage = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
refId,
|
||||
params,
|
||||
}: {
|
||||
refId: string
|
||||
params: AddChatMessageType
|
||||
}) => api.addChatMessage(refId, params),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user