@ubc-farm/async-hoc
v1.1.0
Published
A simple higher order component for React, which gets data from a promise when the component mounts and then adds it to a prop once the promise has resolved.
Downloads
4
Readme
async-hoc
A simple higher order component for React, which gets data from a promise when the component mounts and then adds it to a prop once the promise has resolved.
API
asyncHOC() (default export)
asyncHOC(
promiseFunc: () => Promise,
{
?dataProp: string,
?loadingProp: string,
?errorProp: string
}
): HigherOrderComponent
promiseFunc
is called without any arguments, and the resulting promise
is awaited and the data is set on the prop with the name dataProp
.
dataProp
defaults to 'data'
,
loadingProp
defaults to 'loading'
, and
errorProp
defaults to 'error'
.