React - prop-types (Type checking)


Javascript - (Static) Typing (Checker) in React

PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're using PropTypes.string. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, propTypes is only checked in development mode.


The name property must be a string

import PropTypes from 'prop-types';

class Greeting extends React.Component {
  render() {
    return (
      <h1>Hello, {}</h1>

Greeting.propTypes = {
  name: PropTypes.string


  • PropTypes.string
  • PropTypes.bool,
  • PropTypes.func,
  • elementType,
  • PropTypes.oneOf(['button', 'reset', 'submit']),
  • PropTypes.func.isRequired,
  • PropTypes.object.isRequired
  • PropTypes.arrayOf
            id: PropTypes.string.isRequired,
            title: PropTypes.string.isRequired,

Documentation / Reference

Powered by ComboStrap