JSPM

@muxiu1997/vue-use-cancellable-async-state

0.1.0-rc.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q18053F
  • License MIT

Cancellable version of VueUse `useAsyncState`.

Package Exports

  • @muxiu1997/vue-use-cancellable-async-state

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

License

MIT