@ubc-farm/async-hoc

1.1.0 • Public • Published

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'.

Readme

Keywords

none

Package Sidebar

Install

npm i @ubc-farm/async-hoc

Weekly Downloads

2

Version

1.1.0

License

none

Last publish

Collaborators

  • ubc-farm-team