如何使用swr修复获取错误

时间:2020-11-05 04:28:30

标签: reactjs typescript next.js

我正在使用next.js swr打字稿。
const {data,error} = useSWR([path,JSON.stringify({search})],fetcher);我的的访存程序出现以下错误 请告诉我如何解决。

 No overload matches this call.
     Overload 1 of 3, '(key: keyInterface, config?: ConfigInterface<ICandidates, any, fetcherFn<ICandidates>>): responseInterface<ICandidates, any>', gave the following error.
        Type '(url: any, params: any) => Promise<AxiosResponse<any>>' has no properties in common with type 'ConfigInterface<ICandidates, any, fetcherFn<ICandidates>>'.
      Overload 2 of 3, '(key: keyInterface, fn?: fetcherFn<ICandidates>, config?: ConfigInterface<ICandidates, any, fetcherFn<ICandidates>>): responseInterface<...>', gave the following error.
        Argument of type '(url: any, params: any) => Promise<AxiosResponse<any>>' is not assignable to parameter of type 'fetcherFn<ICandidates>'.
          Type 'Promise<AxiosResponse<any>>' is not assignable to type 'ICandidates | Promise<ICandidates>'.
            Type 'Promise<AxiosResponse<any>>' is not assignable to type 'Promise<ICandidates>'.
              Type 'AxiosResponse<any>' is missing the following properties from type 'ICandidates': page, totalCount, candidates
        16 |     }).then((res) => res);
        17 |   };
      > 18 |   const { data, error } = useSWR<ICandidates>([path, JSON.stringify({ search })], fetcher);
export const useCandidateList = (index: number, search: ISearch) => {
  const path = `${userId}/search/?page=${index}&per_page=${perPage}`;
  const fetcher = (url, params) => {
    return Axios.post(url, {
      headers: { Authorization: `Bearer ${params.accessToken}` },
    }).then((res) => res);
  };
  const { data, error } = useSWR<ICandidates>([path, JSON.stringify({ search })], fetcher);

  return {
    data: data,
    loading: !error && !data,
    error: error,
  };
};

0 个答案:

没有答案