pedrojpj/recompose-extends

View on GitHub
example/waitFor.js

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';
import { compose, withState, withHandlers, pure } from 'recompose';
import { waitFor } from '../src/index';

const WaitFor = ({ items }) => (
  <ul>{items.map(item => <li key={item}>{item}</li>)}</ul>
);

const LoadingComponent = () => <div>Loading...</div>;

export default compose(
  withState('items', 'setItems', []),
  withHandlers({
    loadContent: ({ setItems }) => () =>
      new Promise(resolve =>
        setTimeout(() => {
          const items = ['Cat', 'Dog'];
          setItems(items);
          resolve(true);
        }, 5000)
      )
  }),
  waitFor('loadContent', LoadingComponent),
  pure
)(WaitFor);