@vuefrag/async-state
v1.0.0
Published
Vue 3 reactive async state with loading/error/ready states
Maintainers
Readme
Installation
npm install @vuefrag/async-stateUsage
import { useAsyncState } from '@vuefrag/async-state'
const fetchData = async () => {
await new Promise(resolve => setTimeout(resolve, 100))
return { message: 'Hello from async!' }
}
const { state, isReady, isLoading } = useAsyncState(
fetchData(),
{ message: 'Loading...' }
)
console.log(state.value.message) // 'Loading...'
console.log(isLoading.value) // true
setTimeout(() => {
console.log(state.value.message) // 'Hello from async!'
console.log(isReady.value) // true
}, 200)License
MIT
Extracted from VueUse for standalone use.
