-
Notifications
You must be signed in to change notification settings - Fork 98
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(useAsyncActionHandler): add useAsyncActionHandler hook #1095
Conversation
Preview is ready. |
@@ -0,0 +1,30 @@ | |||
import React from 'react'; | |||
|
|||
export function useAsyncActionHandler<Result>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- What is
Result
? There is no such type in the current namespace - It is not convenient to have generic with а required parameter
@@ -0,0 +1,30 @@ | |||
import React from 'react'; | |||
|
|||
export function useAsyncActionHandler<Result>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow this convention #881
[action], | ||
); | ||
|
||
return [isLoading, handleAction]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change to object here: {isLoading, handler}
. Tuples are primary used for [value, setValue]
const handleAction: typeof action = React.useCallback( | ||
(...args) => { | ||
setLoading(true); | ||
return action(...args).finally(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add check if returned value is a promise before calling finally
815b4e7
to
6313ddb
Compare
6313ddb
to
dc9575e
Compare
@ValeraS ping |
dc9575e
to
a4ccbfa
Compare
a4ccbfa
to
52de79c
Compare
No description provided.