Generate propTypes

Adds missing propTypes definitions for every prop used in a component.

R-Factor will try to guess types of your props based on their name. There are some predefined types:
  • children will be considered PropTypes.node
  • className will be considered PropTypes.string
  • disabled will be considered PropTypes.bool
  • style will be considered PropTypes.object
  • Props prefixed with on will be considered PropTypes.func
  • Props prefixed with is or has will be considered PropTypes.bool
  • If none of the above conditions is met PropTypes.any will be used

How it works

With function component
  • Creates propTypes declaration below the component (if not present)
  • Adds propTypes definitions for every prop used in component (if not present)
  • If propTypes were sorted, sorting will be kept. If not, new propTypes will be added at the end.
With class component
  • Transforms propTypes declaration into a static class property (if present)
  • Creates static propTypes declaration (if not present)
  • Adds propTypes definitions for every prop used in component (if not present)
  • If propTypes were sorted, sorting will be kept. If not, new propTypes will be added at the end.

Works with

  • Functional components defined as an arrow function
  • Functional components defined as a function
  • Class components
  • Higher order functional components defined as an arrow function
  • Higher order functional components defined as a function
  • Higher order class components

Configuration

Packages

  • react
  • prop-types

Examples

© 2018 - 2019 Kamil Mielnik & Yuriy Yakym. All rights reserved.