1.12.12 • Published 6 years ago

recompose-extends v1.12.12

Weekly downloads
32
License
ISC
Repository
github
Last release
6 years ago

Recompose Extends


build status coverage code climate npm version npm downloads

Recompose Extends is a set of utilities that extends the functionality of the Recompose library

npm install recompose-extends --save

Demo

You can see examples of the library at the following url:

https://pedrojpj.github.io/recompose-extends/

Higher-order components

removeProp()

const enhance = compose(withProps({ counter: 0 }), removeProp('counter'))
const Counter = enhance(({ counter }) =>
  <div>
    Count: {counter}
  </div>
)

Eliminates props that are not going to be used by the inferior components

waitFor()

const View = () => <div>Loaded</div>;

const loadPromise = () => new Promise(resolve => {
  setTimeout => (() => resolve(true), 3000)
})

const enhance = compose(
  withProps({ promise: loadPromise()}),
  waitFor(['promise']))
  (View)

Wait for one or more promises before rendering the component

withActions()

export default compose(
  withReducer('state', 'dispatch', reducer, initialState),
  withActions({ increment, decrement }),
  pure
)(View);

To use with the component withReducer, you can create props as curry functions that receive the dispatch and status by default. Similar to Redux's connect

withErrors()

const WithErrors = ({ example }) => <div>{example()}</div>;

export default compose(withErrors({ debug: true }), pure)(WithErrors);

Adds an error handler in the component allowing you to visualize the chain of errors in debug mode or prevent the rendering of other components from failing. Similar to the componctDidCatch of React

withModal()

export default compose(
  withState('modal', 'setModal', false),
  withModal(({ modal }) => modal, Modal, ({ setModal }) => ({
    onClose: () => setModal(false)
  })),
  pure
)(WithModal);

High order component used to render another component in portal mode next to our base component. Useful for manners or tooltips

withForm()

const Form = ({ form, updateForm, submitForm }) => (
  <form>
    <input type="text" name="name" value={form.name} onChange={updateForm} />
    <button type="submit" onClick={submitForm}>
      Send
    </button>
  </form>
);

const enhance = compose(
  withForm(
    {
      name: { value: '', required: true }
    },
    () => () => {
      console.log('form submitted');
    }
  )
)(Form);

High order component that allows to manage a form, includes validation of required fields

withRefs()

const WithRefs = ({ setRef }) => (
  <button className="btn btn-primary" ref={r => setRef('button', r)}>
    Example
  </button>
);

export default compose(
  withRefs(),
  lifecycle({
    componentDidMount() {
      console.log(this.props.getRef('button'));
    }
  }),
  pure
)(WithRefs);

High order component for easy access to React refs using recompose

withChildren()

const Component = ({ ComponentButton }) => <div>{ComponentButton}</div>;


const WithChildren = compose(
  withChildren(['button']),
)(Component);


<WithChildren><button>Example</button><div /></WithChildren>

High order component for to filter and select children, destroy the children by building a prop for each of the selected children to place them in the parent as you wish

1.12.12

6 years ago

1.12.11

6 years ago

1.12.10

6 years ago

1.12.9

6 years ago

1.12.8

6 years ago

1.12.7

6 years ago

1.12.6

6 years ago

1.12.5

6 years ago

1.12.4

6 years ago

1.12.3

6 years ago

1.12.2

6 years ago

1.12.1

6 years ago

1.12.0

6 years ago

1.11.8

6 years ago

1.11.7

6 years ago

1.11.6

6 years ago

1.11.5

6 years ago

1.11.4

6 years ago

1.11.3

6 years ago

1.11.2

6 years ago

1.11.1

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.9.11

6 years ago

1.9.10

6 years ago

1.9.9

6 years ago

1.9.8

6 years ago

1.9.7

6 years ago

1.9.6

6 years ago

1.9.5

6 years ago

1.9.4

6 years ago

1.9.3

6 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago