Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: callback params add request parameter args #3

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

wangcch
Copy link
Contributor

@wangcch wangcch commented Jul 24, 2024

export type RequestCallbackFn<T extends Request> = {
  onCompleted?: (
    data: Payload<T, true>,
    response: Payload<T>,
+   args: Parameters<T>,
  ) => void;
  onError?: (
    err: RequestError<Payload<T>, BodyData<T>>,
+   args: Parameters<T>,
  ) => void;
};

useRequest

const [createRequest, { hasPending, cancel }] = useRequest(
  (id: string) =>
    request<UserDetail>({
      url: `/user/${id}`,
      method: "DELETE",
    }),
  {
    onCompleted: (data, response, paramsArgs) => console.info(data, response, paramsArgs),
    onError: (err, paramsArgs) => console.info(err, paramsArgs),
  },
);
// [string]
// paramsArgs

useResource

const params = reactive({ id: userId });
const [reqState, request] = useResource(
  ({ id }?: { id: string }) =>
    request<UserDetail>({
      url: `/user/${id}`,
      method: "GET",
    }),
  [params],
  {
    onCompleted: (data, response, paramsArgs) => console.info(data, response, paramsArgs),
    onError: (err, paramsArgs) => console.info(err, paramsArgs),
  },
);
// [{ id: string } | undefined]
// paramsArgs

@wangcch wangcch changed the base branch from main to dev July 24, 2024 15:52
@wangcch wangcch merged commit 924f655 into dev Jul 25, 2024
3 checks passed
@wangcch wangcch deleted the feat-callback-req-params branch July 25, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant