1.2.6 • Published 5 years ago

@humblejs/data-provider v1.2.6

Weekly downloads
4
License
Apache-2.0
Repository
-
Last release
5 years ago

DataProvider

Provides JSON data from remote api

Demo

Install

yarn add @humblejs/data-provider

Usage

import createDataProvider from '@humblejs/data-provider';

const { DataProvider, withData } = createDataProvider();

const App = () => (
  <DataProvider url="/api/v1/data">
    <MyComponent />
  </DataProvider>
);
const MyComponent = ({ data }) => (
  <div>My address is {data.ADDRESS}</div>
);

export default withData(MyComponent, [
  'ADDRESS',
]);

Advanced

For JSON Array response

withData(MyComponent, '*')

...

Array.isArray(props.data.items) // == true

For custom key name

withConfig(MyComponent, '*', 'staff')

...

Array.isArray(props.staff.items) // == true