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

[RFC] useLockFn #562

Closed
awmleer opened this issue Aug 2, 2020 · 2 comments · Fixed by #703
Closed

[RFC] useLockFn #562

awmleer opened this issue Aug 2, 2020 · 2 comments · Fixed by #703
Assignees
Labels
feature New feature or request

Comments

@awmleer
Copy link
Collaborator

awmleer commented Aug 2, 2020

用于给一个异步函数增加竞态锁,防止并发执行,例如可以避免表单的重复提交。

API

function useLockFn<T>(fn: T): T

Demo

const submit = useLockFn(async () => {
  await api.doSubmit(...)
  message.success()
})

return (
  <button onClick={submit}>Submit</button>
)
@awmleer awmleer added the feature New feature or request label Aug 2, 2020
@awmleer awmleer self-assigned this Aug 2, 2020
@brickspert
Copy link
Collaborator

能举一些使用场景的例子吗?

避免表单的重复提交,一般都是用 useRequest/useAsync,点击后 button 变 loading 态。
表单场景肯定不需要 useLockFn~~

还有其它场景吗?

@brickspert
Copy link
Collaborator

+1

@awmleer awmleer added this to the v2.6.0 milestone Aug 9, 2020
@awmleer awmleer mentioned this issue Nov 2, 2020
@awmleer awmleer removed this from the v2.6.0 milestone Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants