create-react-factory
create-react-factory create a factory for your react component. It allows you to:
- compose multiple high order components
- set a custom component to render using the component property
Installation
npm install create-react-factory
Usage
// Underline.js const Underline = <Component style=...style textDecoration: 'underline' ...props />const factory =
// Strong.js const Strong = <Component style=...style fontWeight: 'bold' ...props />const factory =
// Red.js const Red = <Component style=...style color: 'red' ...props />const factory =
// RedStrongUnderline.js const RedStrongUnderline =
// output:// <ul>// <li style="color: red; font-weight: bold; text-decoration: underline;">// Hello World!// </li>// </ul>
Why?
Because with the "traditional" factory approach, the component property is overridden by the Component passed to the factory. Thus it become impossible to set a different component to render.