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

在组件销毁时,执行useRequest生成的runAsync方法,不会触发onSuccess方法等,貌似任务被挂起 #2674

Open
panfengde opened this issue Nov 18, 2024 · 4 comments

Comments

@panfengde
Copy link

const { runAsync: runEditBeam } = useRequest(
     params => {
       return beamSetData?.treatmentTechnique === TreatmentTechnique.PencilBeamScanning
         ? editBeam(params)
         : editUSBeam(params)
     },
     {
       manual: true,
       ready: !isNil(beamSetData),
       onSuccess: () => {
         dispatch(versionActions.setVersion())
       },
     },
   )

runEditBeam方法会透穿给子组件。
在子组件销毁(当前组件也会)时,执行runEditBeam方法,会出现onSuccess不执行的异常。
同时,子组件中的try runEditBeam catch也被吃掉。

@ruixingshi
Copy link
Contributor

按照ahooks官网网站的介绍,组件卸载时,onSuccess确实是不执行的:
image

@panfengde
Copy link
Author

hooks官网网站的介绍,组件卸载时

sorry,没注意到。

但是在一些场景下,就不好用了。
比如将方法交给input控件的onBlur事件,

这时,组件的销毁,触发onblur事件。

但是这个onSuccess方法将不再会在触发了。
这不好用

@ruixingshi
Copy link
Contributor

不好用

同感。比较常见的场景是,在弹窗里,点完确定/取消,希望触发回调方法更新数据时,如果弹窗先关闭(弹窗组件卸载),就无法更新数据了。

@panfengde
Copy link
Author

同感。比较常见的场景是,在弹窗里,点完确定/取消,希望触发回调方法更新数据时,如果弹窗先关闭(弹窗组件卸载),就无法更新数据了。

暂时先用useCallback或useMemoizedFn方式解决了。

希望大佬么考虑一下-__-

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

No branches or pull requests

2 participants