/react-omit-own-props

A factory to omit react props by propTypes

Primary LanguageJavaScriptMIT LicenseMIT

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 it 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>;