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

Add "onSuccess" option for "useAsyncState" function #2560

Closed
4 tasks done
only52607 opened this issue Dec 20, 2022 · 2 comments
Closed
4 tasks done

Add "onSuccess" option for "useAsyncState" function #2560

only52607 opened this issue Dec 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@only52607
Copy link

Clear and concise description of the problem

I'm using the useAsyncState function, which provides a useful onError option to do something on failure. Also, I often do something else after a successful execution, but I don't seem to see an option like onSuccess in the type definition of the UseAsyncStateOptions interface. I wonder if it would be useful to add a similar onSuccess option.

Suggested solution

Add an onSuccess option to the UseAsyncStateOptions interface.

Alternative

I achieved my purpose by using the following code, but I think providing onSuccess option can save writing these boilerplate codes.

const { state, isReady, isLoading } = useAsyncState(
  axios
    .get('https://jsonplaceholder.typicode.com/todos/1')
    .then(t => t.data),
  { id: null },
)

watch(() => isReady.value, () => {
  if(isReady.value) {
    doSomething()
  }
})

Additional context

No response

Validations

@only52607 only52607 added the enhancement New feature or request label Dec 20, 2022
@wolodev
Copy link

wolodev commented Dec 20, 2022

I'll create a PR on it

@Alfred-Skyblue
Copy link
Member

Alfred-Skyblue commented Dec 20, 2022

我会在上面创建一个 PR

Already PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants