3 ms·
You can think of it very similarly to `useState`, where it returns a particular state and a function to update that state. With `useState`: const [ firstS
by loh 5y ago
You can think of it very similarly to `useState`, where it returns a particular state and a function to update that state.
With `useState`:
const [ firstState, setFirstState ] = useState('alpha')
const [ secondState, setSecondState ] = useState('beta')
With `usePromise`:
const [ firstPromiseState, readFirstThing ] = usePromise(read)
const [ secondPromiseState, readSecondThing ] = usePromise(read)
To initialize the promise state similar to `useState('alpha')`:
const [ firstPromiseState, readFirstThing ] = usePromise(read, { status: 'resolved', value: 'alpha' })
const [ secondPromiseState, readSecondThing ] = usePromise(read, { status: 'resolved', value: 'beta' })