@muxiu1997/vue-use-cancellable-async-state
v0.1.0-rc.1
Published
Cancellable version of VueUse `useAsyncState`.
Downloads
1
Maintainers
Readme
vue-use-cancellable-async-state
Cancellable version of VueUse useAsyncState
Install
$ npm install @muxiu1997/vue-use-cancellable-async-state
import useCancellableAsyncState from '@muxiu1997/vue-use-cancellable-async-state'
Usage
import axios from 'axios'
import useCancellableAsyncState from '@muxiu1997/vue-use-cancellable-async-state'
const { state, isReady, isLoading } = useCancellableAsyncState(
(onCancel) => {
const abortController = new AbortController()
onCancel(() => abortController.abort())
const id = args?.id || 1
return axios.get(
`https://jsonplaceholder.typicode.com/todos/${id}`,
{ signal: abortController.signal },
)
},
{},
)