Skip to content

Latest commit

 

History

History
46 lines (40 loc) · 1.55 KB

README.md

File metadata and controls

46 lines (40 loc) · 1.55 KB

propper

npm (scoped) Travis Codecov branch David GitHub issues npm

Reduce React props on the fly without redux

Example

Propped Component:

import { propper } from '@overlaylabs/propper'
import React from 'react'

// standard React components
class MyComponent extends React.Component {}

// function (much like mapStateToProps) which reduces props
const reduceProps = ({ items }) => {
  return {
    visibleItems: items.filter(item => item.visbile)
  }
}

// wrap the component
export default propper(reduceProps)(MyComponent)

Parent Component:

import MyComponent from 'myComponent'
import React from 'react'

// standard React Component
class ParentComponent extends React.Component {
  render() {
    const itemProps = [
      { id: 1, visible: true },
      { id: 2, visible: false },
      { id: 3, visible: true }
    ]
    return (<MyComponent items={itemProps} />);
  }
}