File size: 688 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { useQuery } from "@tanstack/react-query";
import React from "react";
import InvariantService from "#/api/invariant-service";

type ResponseData = string;

interface UseGetPolicyConfig {
  onSuccess: (data: ResponseData) => void;
}

export const useGetPolicy = (config?: UseGetPolicyConfig) => {
  const data = useQuery<ResponseData>({
    queryKey: ["policy"],
    queryFn: InvariantService.getPolicy,
  });

  const { isFetching, isSuccess, data: policy } = data;

  React.useEffect(() => {
    if (!isFetching && isSuccess && policy) {
      config?.onSuccess(policy);
    }
  }, [isFetching, isSuccess, policy, config?.onSuccess]);

  return data;
};