-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
XRequest 是否可以支持打断 #458
Comments
在使用 Ant Design X 的 XRequest 发起请求时,确实可以通过自定义 fetch 的方式来主动终止请求。你可以使用
以下是一个示例代码: const controllerRef = useRef<AbortController | null>(null);
controllerRef.current = new AbortController();
const { signal } = controllerRef.current;
const exampleRequest = () => {
const mockFetch = fetch(BASE_URL + PATH, { signal });
return XRequest({
baseURL: BASE_URL + PATH,
model: MODEL,
fetch: mockFetch,
});
};
const onRequest = await exampleRequest.create(
...
};
<Sender
onSubmit={(nextContent) => {
onRequest(nextContent);
}}
onCancel={() => controllerRef.current?.abort();}
/> 在这个示例中,当用户点击取消按钮时, 提议的 API如果你希望在 controllerRef.current = new AbortController();
const { signal } = controllerRef.current;
XRequest({
baseURL: BASE_URL + PATH,
model: MODEL,
signal: signal
}); 这种方式可以使得请求的终止更加直观和简洁。 通过这种方式,你可以有效地控制请求的生命周期,避免不必要的网络请求和资源浪费。 Learn more: |
感觉可以提个PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
需求动机
使用 XRequest 发起请求后,希望能主动终止请求。目前是否能通过自定义 fetch 的方式实现?
提议的 API 是什么样的?
The text was updated successfully, but these errors were encountered: