question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add some features from useFetch also to useAxios

See original GitHub issue

Currently useFetch has execute(), but useAxios does not. This means that with useFetch you can first create useFetch, set {immediate: false}, then execute() the call later, but with useAxios it fires immediately when you call useAxios.

Abort is also missing in useAxios.

Some properties don’t make sense to add into axios such as statusText (since that’s just in the axios response).

Another thing is that the returned property names are different in useAxios and useFetch, but changing that’d be a breaking change.

Exposed logic from both logics:

useAxios
  response: Ref<AxiosResponse<T> | undefined>
  data: Ref<T | undefined>
  finished: Ref<boolean>
  loading: Ref<boolean>
  canceled: Ref<boolean>
  error: Ref<AxiosError<T> | undefined>
useFetch
  isFinished: Ref<boolean>
  statusCode: Ref<number | null>
  response: Ref<Response | null>
  error: Ref<any>
  data: Ref<T | null>
  isFetching: Ref<boolean>
  canAbort: ComputedRef<boolean>
  aborted: Ref<boolean>
  abort: Fn
  execute: () => Promise<any>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
antfucommented, Apr 13, 2021

Would love to align those interfaces. We can make aliases and for APIs and mark some as deprecated. Then drop them in along with the next major.

1reaction
antfucommented, Apr 14, 2021

Aligning with useFetch looks better to me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axios vs. fetch(): Which is best for making HTTP requests?
The fetch() API is perfectly capable of reproducing the key features of Axios, and it has the added advantage of being readily available...
Read more >
useAxios : A simple custom hook for calling APIs using axios
Add withAxios HOC to wrap and inject these properties into any "dumb" component. Provide an example extending the hook to tailored hooks: const ......
Read more >
useFetch - VueUse
The following URLs can be used to test different features of useFetch ... You can read more about the suspense api in the...
Read more >
How to Fetch Data in React With A Custom useFetch Hook
In this video I will show how to make a custom useFetch hook in react. The hook allows you to fetch data from...
Read more >
useFetch — A Custom React Hook - Medium
Without using a custom hook, you would probably do something similar to this: ... Let's start to add the features I mentioned above....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found