0.0.1 • Published 6 years ago

react-omit-own-props v0.0.1

Weekly downloads
39
License
MIT
Repository
github
Last release
6 years ago

A factory to omit react props by propTypes

A case is when you don't have destruction in class render method and want to keep in clean and readable.

import makeOmitter from 'react-omit-own-props';

const PROP_TYPES = { children: PropTypes.node };
const omit = makeOmitter(PROP_TYPES);

export default class ExampleComponent extends Component {
  static propTypes = PROP_TYPES;
  render = () =>
    <div {...omit(this.props)}>
      {this.props.children}
    </div>
}

In functions you normally use destruction:

const MyComponent = ({ children, ...rest }) =>
  <div {...rest}>
    {children}
  </div>;