Source

apis/SignUp.js

import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "react-toastify";
import Axios from "../utils/ApiConfiguration";
/**
 * Custom hook to register a new user.
 *
 * This hook sends a POST request to register a new user on the server.
 *
 * @param {Object} data - The user registration data to be submitted.
 *
 * @returns {Object} The mutation result object.
 *
 * @example
 * // Usage of useRegisterUser hook
 * const { mutate, isLoading, isError, error } = useRegisterUser();
 * const registrationData = {  ...  };
 * mutate(registrationData);
 */
export const useRegisterUser = () =>
  useMutation((data) => Axios.post("auth/register/", data), {
    onError: (err) => {
      let temp = Object.values(err?.response?.data?.errors || {});
      toast.error(temp[0][0]);
    },
  });