0.1.0-rc.1 • Published 5 months ago

@muxiu1997/vue-use-cancellable-async-state v0.1.0-rc.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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 },
    )
  },
  {},
)

License

MIT