react-omit-own-props

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i react-omit-own-props

Weekly Downloads

10

Version

0.0.1

License

MIT

Unpacked Size

4.18 kB

Total Files

5

Last publish

Collaborators

  • droganov