usePromiseMachine
Because having to set loading
and error
and doing some if (data)
for promises is boring 🙃.
Features
- Know instantly which state your promise is in via
myPromise.state
(->PENDING
||FULFILLED_DATA
||FULFILLED_EMPTY
||REJECTED
) - Easily access the error or the data via
myPromise.error
ormyPromise.data
- Don't bother guessing if you're getting back an empty container (
[]
or{}
). If it's the case,myPromise.state
will beFULFILLED_EMPTY
- No need to remember the existing states, they're all available via
usePromiseMachine.STATES.*
- Simpler code, safe, 0 brain power required 🥳
Install
npm i use-promise-machine -D
Use
Fun facts
- You can access every state the promise can be in by using the
usePromise.STATES
variable. - The
usePromise.STATES.FULFILLED_EMPTY
means your promise returns either an emptyarray
or an emptyobject
Learn more
Check the tests folder in src/usePromise.spec.ts
or tweet me 😉