On this page

09. What are the different data types available in React.PropTypes?

📄 Noteseasy#proptypes#props#validation#typescript
Also asked as:
  • What are different types of PropTypes?

Short answer

The prop-types package (formerly React.PropTypes) provides validators for primitives (string, number, bool, func, array, object, symbol, bigint), renderables (node, element, elementType), specific values (oneOf, instanceOf), compound shapes (oneOfType, arrayOf, objectOf, shape, exact), and any. Any validator can be chained with .isRequired. In modern React 19 code, the same constraints are expressed with TypeScript types.

Explanation

PropTypes are like labels on storage boxes: "books only", "fragile", "must not be empty". They do not stop you from packing the wrong thing, but they warn you (in development) when you do.

Validator reference

ValidatorAcceptsTypeScript equivalent
PropTypes.stringStringstring
PropTypes.numberNumbernumber
PropTypes.boolBooleanboolean
PropTypes.funcFunction() => void
PropTypes.arrayAny arrayunknown[]
PropTypes.objectAny objectobject / Record<string, unknown>
PropTypes.symbolSymbolsymbol
PropTypes.bigintBigIntbigint
PropTypes.nodeAnything renderable (string, number, element, array, fragment)React.ReactNode
PropTypes.elementA single React elementReact.ReactElement
PropTypes.elementTypeA component type (Button, "a")React.ElementType
PropTypes.instanceOf(Date)Instance of a classDate
PropTypes.oneOf(["sm", "md"])One of listed values (enum)"sm" | "md"
PropTypes.oneOfType([...])One of several typesstring | number
PropTypes.arrayOf(PropTypes.number)Array of a typenumber[]
PropTypes.objectOf(PropTypes.number)Object with values of a typeRecord<string, number>
PropTypes.shape({...})Object with known keys (extra keys allowed){ id: number; name?: string }
PropTypes.exact({...})Object with exactly these keysExact object type
PropTypes.anyAnythingany / unknown
.isRequiredMakes any validator requiredNon-optional property

You can also write a custom validator: a function (props, propName, componentName) that returns an Error when invalid.

⚠️ Gotcha: React 19 removed propTypes checking from React, so these warnings no longer appear for function components. Know them for legacy codebases and interviews, but use TypeScript for new code.

Example

import PropTypes from "prop-types";

function ProductCard({ title, price, tags, status, author, onBuy, icon: Icon, footer }) {
  return (
    <article>
      {Icon && <Icon aria-hidden />}
      <h3>{title}</h3>
      <p>${price.toFixed(2)} - {status}</p>
      <p>By {author.name}</p>
      <ul>{tags.map((t) => <li key={t}>{t}</li>)}</ul>
      <button onClick={onBuy}>Buy</button>
      {footer}
    </article>
  );
}

ProductCard.propTypes = {
  title: PropTypes.string.isRequired,
  price: PropTypes.number.isRequired,
  tags: PropTypes.arrayOf(PropTypes.string),
  status: PropTypes.oneOf(["in-stock", "sold-out"]),
  author: PropTypes.shape({
    name: PropTypes.string.isRequired,
    id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  }).isRequired,
  onBuy: PropTypes.func.isRequired,
  icon: PropTypes.elementType,
  footer: PropTypes.node,
  sku(props, propName, componentName) {
    if (props[propName] && !/^[A-Z]{3}-\d+$/.test(props[propName])) {
      return new Error(`Invalid ${propName} supplied to ${componentName}`);
    }
    return null;
  },
};

Common mistakes

  • Writing PropTypes.boolean or PropTypes.function; the correct names are bool and func.
  • Confusing element (a single element) with node (anything renderable, including strings and arrays).
  • Using shape when you need to reject extra keys; that is exact.
  • Importing from react (React.PropTypes) instead of the prop-types package.

Follow-up questions

  • element vs elementType? element is a rendered instance like <Icon />; elementType is the component itself, like Icon, that you render later.
  • Do PropTypes add bundle size in production? The package was small and checks were skipped in production; tools like babel-plugin-transform-react-remove-prop-types stripped them entirely.
  • Why did the ecosystem move to TypeScript? Compile-time errors, editor autocompletion and no runtime cost, with richer types than PropTypes can express.

Quick recap

  • Primitives: string, number, bool, func, array, object, symbol, bigint.
  • Renderables: node, element, elementType.
  • Structured: oneOf, oneOfType, arrayOf, objectOf, shape, exact, instanceOf.
  • Chain .isRequired; use TypeScript in React 19 projects.