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

chore: add onCancel for useRequest #2694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lqr131115
Copy link

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

  1. useRequest对外暴露的cancel本质上是JS层的中断,并且没有对应生命周期回调。因此增加onCancel,用于请求取消时的额外操作,如用户行为埋点、请求服务的真实取消等。
  2. 列出最终的 API 实现和用法。
const { loading, data, cancel } = useRequest( service, { onCancel?: () => {
   console.log('do here when cancel trigger')
}}
  1. 涉及UI/交互变动需要有截图或 GIF - 无。

📝 更新日志

语言 更新描述
🇨🇳 中文 组件卸载时 onCancel生命周期 不会被触发

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants