An open API service indexing awesome lists of open source software.

https://github.com/pfgray/chainable-components

A composable API for reusable React code.
https://github.com/pfgray/chainable-components

Last synced: 2 months ago
JSON representation

A composable API for reusable React code.

Awesome Lists containing this project

README

        

# Chainable Components
_A composable API for reusable React code._

Chain together reusable React components:
```jsx
withState(0).chain(outer =>
withState(outer.value + 5).map(inner =>
({inner, outer})
)
).render(({inner, outer}) => (


Outer: {outer.value} outer.update(outer.value + 1)}>+

Inner: {inner.value} inner.update(inner.value + 1)}>+


));
```

Transform HOCs and Render Props to chainables and back:

![Chainable pipeline](docsSrc/chainable-pipeline.png?raw=true "Chainable pipeline")

:point_down: Here's a blog post that introduces the API.
[https://paulgray.net/chainable-components](https://paulgray.net/chainable-components)

Example:
```jsx
import { Route } from 'react-router';
import { connect } from 'react-redux';

const withConnect = fromHigherOrderComponent(connect(mapState, mapDispatch));
const withRoute = fromRenderProp(Route);

// withConnect and withRoute are now chainable!
const withConnectAndRoute =
withConnect.chain(storeProps =>
withRoute.map(route => ({
store: storeProps,
path: route.history.location.pathname
})));

// then render it!
withConnectAndRoute.render(({store, path}) => (


current path is: {path}
store contains: {store.users}

));

// or convert it back render prop:
const ConnectAndRoute = withConnectAndRoute.toRenderProp();

{({store, path}) => (


current path is: {path}
store contains: {store.users}

)}

// or convert it back to a HOC:
const connectAndRouteHoc = withConnectAndRoute.toHigherOrderComponent(p => p);

connectAndRouteHoc(({store, path}) => (


current path is: {path}
store contains: {store.users}

));
```