You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All hooks that need queryKey should return the corresponding querykey in the returned object. Because I have dynamically inherited hooks and I need to access their derived hooks in related components.
I am sharing an example of the problem below
constusePagination=<SearchParamsextendsPaginationSearchParams<any,string,string,string>,Response>(aliasses: string[],path: string)=>(filters?: SearchParams["filters"],extraOptions?: Omit<SearchParams,"filters"/* | "page" | "size" */>,queryOptions: Omit<UseQueryOptions<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>,"queryKey"|"queryFn">={},config?: AxiosRequestConfig<Response>)=>{constsearchFilters=filters===undefined||filters===null ? newURLSearchParams() : createPagination<SearchParams>(filters,extraOptions);// const searchFilters = useMemo(() => {// if (filters === undefined || filters === null) {// console.log("filters is null");// return new URLSearchParams();// }// return createPagination<SearchParams>(filters, extraOptions);// }, [filters, extraOptions]);returnuseQuery<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>({queryKey: [aliasses,searchFilters.toString()].flat(),queryFn: ({ signal })=>{config=modifyConfig<Response>(config,signal);returnAPI.get<Response>(path,Object.assign({},{params: searchFilters},config));},
...queryOptions,});};constuseSearch=<SearchextendsSearchParams<unknown,string,string,string>,Response>(aliasses: string[],path: string)=>(filters?: Search["filters"],extraOptions?: Omit<Search,"filters">,queryOptions: Omit<UseQueryOptions<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>,"queryKey"|"queryFn">={},config?: AxiosRequestConfig<Response>)=>{constsearchFilters=filters===undefined||filters===null ? newURLSearchParams() : createSearchParams<Search>(filters,extraOptions);// const searchFilters = useMemo(() => {// if (filters === undefined || filters === null) {// console.log("filters is null");// return new URLSearchParams();// }// return createSearchParams<Search>(filters, extraOptions);// }, [filters, extraOptions]);returnuseQuery<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>({queryKey: [aliasses,searchFilters.toString()].flat(),queryFn: ({ signal })=>{config=modifyConfig<Response>(config,signal);returnAPI.get<Response>(path,Object.assign({},{params: searchFilters},config));},
...queryOptions,});};constuseFind=<ParamsextendsURLParamsType,Response>(aliasses: string[],path: string)=>(params: Params,queryOptions: Omit<UseQueryOptions<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>,"queryKey"|"queryFn">={},config?: AxiosRequestConfig<Response>)=>{if(!params){console.warn(`["${path}"]:> No params provided, cannot make API request. Please provide params.`);}returnuseQuery<AxiosResponse<Response>,AxiosError<APIErrorTypes>,AxiosResponse<Response>>({queryKey: [aliasses,params].flat(),queryFn: ({ signal })=>{letmatchedURL: string|null=null;matchedURL=matchVariablesToKeys(path,params);if(matchedURL===null)thrownewError("No variables found in path");returnAPI.get<Response>(matchedURL,Object.assign({},config,{ signal }));},
...queryOptions});};
Below are the new hooks I inherited from the core functions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
All hooks that need queryKey should return the corresponding querykey in the returned object. Because I have dynamically inherited hooks and I need to access their derived hooks in related components.
I am sharing an example of the problem below
Below are the new hooks I inherited from the core functions.
Beta Was this translation helpful? Give feedback.
All reactions