Ladda-react provides helper functions to easily integrate React apps with the data caching library Ladda.
npm install --save ladda-react
withData
is a HOC that takes a configuration object and enriches an existing component by injecting state management.
import { withData } from 'ladda-react';
const config = {
resolve: {
mails: (props) => api.getMails(props.userId), // api.getMails() returns a promise
},
pendingComponent: () => <LoadingComponent />,
errorComponent: () => <ErrorComponent />
// ... and more! Check "Config" for more options.
};
return withData(config)(MyComponent);
// => MyComponent will have `userId` and `mails` available as props.
Key | Type |
---|---|
observe | object |
resolve | object |
paginate | object |
poll | object |
pendingComponent | React Component |
errorComponent | React Component |
More details to follow.
npm install