import { useMutation, useQuery } from "@tanstack/react-query";
import axios from "axios";
/**
* Custom hook to send a chat message.
*
* @async
* @returns {import("@tanstack/react-query").UseMutationResult} The mutation result object.
*
* @param {object} data - The data to send in the chat message.
* @param {string} data.message - The chat message text.
*
* @example
* const { mutate, isLoading, isError } = useGetChats();
*
* const sendMessage = async (message) => {
* try {
* await mutate({ message });
* } catch (error) {
* console.error(error?.message);
* }
* };
*/
export const useGetChats = () =>
useMutation({
mutationKey: ["chatbot"],
mutationFn: (data) =>
axios.post(`https://dev.psms.rkdholdings.com.np/api/chat/`, data),
onError: (err) => {
console.log(err?.message);
},
});
Source