Our primary goals are
- Provides react hooks, state, utils, and more.
npm install --save simple-boot-react
manage the state of the promise.
function Component() {
const data = usePromiseState({
factory: () => Promise.resolve('hello')
})
return (<div>
<div>{data.state}</div>
<div>{data.isError}</div>
<div>{data.isLoading}</div>
<div>{data.isSuccess && data.data}</div>
</div>)
}
- usePromiseState<T, RP>: StateHook - T is Promise return type, RP is Factory Parameters type
- factory: () => Promise - promise factory
- success: (data: T) => void - success callback
- error: (error: any) => void - error callback
- manual: boolean - if true, the promise is not executed automatically.
- signal: (type: 'retry' | 'success' | 'error' | 'loading' | 'ready', data: StateHook) => void - signal callback
- executeConfig: { noCacheLoad?: boolean, retry?: number }
function Component() {
usePromiseCleanUp(() => {
return new Promise<() => void>((resolve, reject) => {
//cleanUp function return
resolve(() => {
console.log('cleanUp')
})
});
}, [data])
return <div></div>
}
function Component() {
const notFalsyData = useNotFalsy((data) => {
return data.length;
}, 'data');
return <div>{notFalsyData.length}</div>
}
function Component() {
useNotFalsyCallBackCleanUp((data) => {
return () => {
console.log('useNotFalsyCallBackCleanUp cleanUp')
}
}, data)
return <div></div>
}
function Component() {
const notNullishData = useNotNullish((data) => {
return data.length;
}, 'data');
return <div>{notNullishData}</div>
}
function Component() {
useNotNullishCallBackCleanUp((data) => {
return () => {
console.log('useNotNullishCallBackCleanUp cleanUp')
}
}, data)
return <div>{notNullishData}</div>
}
function Component() {
return <div></div>
}
function Component() {
useObservableUnsubscribe(() => {
return subject.pipe(debounceTime(500), distinctUntilChanged()).subscribe(it => {
// ...
})
})
return <div></div>
}
function Component() {
return <div></div>
}
function Component() {
return <div></div>
}
function Component() {
return <div></div>
}
function Component() {
return <div></div>
}
function Component() {
return <div></div>
}