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

useAxios may need to provide hooks #2713

Closed
4 tasks done
jbaubree opened this issue Feb 1, 2023 · 1 comment · Fixed by #2714
Closed
4 tasks done

useAxios may need to provide hooks #2713

jbaubree opened this issue Feb 1, 2023 · 1 comment · Fixed by #2714
Labels
enhancement New feature or request

Comments

@jbaubree
Copy link
Contributor

jbaubree commented Feb 1, 2023

Clear and concise description of the problem

When we use fetching APIs like fetch or axios, we need almost all the time to work with data, specially setting mapping response data.
Currently, the only solution i found to do that with useAxios is using watcher and i find this not optimize:

const { data, isFinished } = useAxios('/api/posts')
watch(isFinished, (value), {
  if (value && data.value)
    mapAndSetMyData(data.value)
})

Suggested solution

Add hooks like onFetchResponse, onFetchError and onFetchEnd like this is setup on useFetch

I dont know the best way to do it so i can't create PR for that, i hope that this idea will be found good and someone can implement this feature.
This will be awesome.

Alternative

No response

Additional context

No response

Validations

@jbaubree jbaubree added the enhancement New feature or request label Feb 1, 2023
@Alfred-Skyblue
Copy link
Member

Alfred-Skyblue commented Feb 1, 2023

I think a parameter should be added to the options to monitor the callback function of the success or failure of the request. I have created a PR, and I hope the author can adopt it.

const onSuccess = (result) => {
  console.log("Success!", result);
};
useAxios("/api/posts", { method: "POST" }, { onSuccess });

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

Successfully merging a pull request may close this issue.

2 participants