You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

create-react-factory

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-react-factory

React component factory factory

0.2.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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
import React from 'react'
import createReactFactory from 'create-react-factory'

export const Underline = ({component: Component = 'div', style = {}, ...props}) => (
  <Component style={{...style, textDecoration: 'underline'}} {...props} />
)
export default Underline
export const factory = createReactFactory(Underline)
// Strong.js
import React from 'react'
import createReactFactory from 'create-react-factory'

export const Strong = ({component: Component = 'div', style = {}, ...props}) => (
  <Component style={{...style, fontWeight: 'bold'}} {...props} />
)
export default Strong
export const factory = createReactFactory(Strong)
// Red.js
import React from 'react'
import createReactFactory from 'create-react-factory'

const Red = ({component: Component = 'div', style = {}, ...props}) => (
  <Component style={{...style, color: 'red'}} {...props} />
)
export default Red
export const factory = createReactFactory(Red)
// RedStrongUnderline.js
import {factory as strongFactory} from './Strong'
import {factory as redFactory} from './Red'
import Underline from './Underline'

export const RedStrongUnderline = strongFactory(redFactory(Underline))
export default RedStrongUnderline
import React from 'react'
import {render} from 'react-dom'
import Rsu from './RedStrongUnderline'

render(<ul><Rsu component="li">Hello World!</Rsu></ul>, document.getElementById('root'))
// 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.

License

MIT

FAQs

Package last updated on 15 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts