ReactEasy
What are PropTypes?
PropTypes are runtime prop type checks from the prop-types package: you declared Component.propTypes = { name: PropTypes.string.isRequired } and React warned in development when props did not match. React 19 removed PropTypes checking for function components (they are silently ignored), and TypeScript is now the standard way to type props.
How they worked
PropTypes.string,number,bool,func,node,element,arrayOf(),shape(),oneOf(),.isRequired.- Checks ran only in development and produced console warnings, never errors.
Status today
- React 15.5 moved them out of the core into
prop-types. - React 19 no longer runs
propTypeschecks for function components; the package itself has not been updated since 2023. - Class components may still use them, but the ecosystem has moved on.
TypeScript instead
- Checks at compile time, in your editor, before code runs.
- Covers props, state, hooks, events and context.
- Discriminated unions model variants (
{ kind: "link"; href: string } | { kind: "button"; onClick: () => void }).
Runtime validation still matters
TypeScript types disappear at runtime. For untrusted data (API responses, form input, URL params), validate with a schema library such as Zod or Valibot, and infer TypeScript types from the schema.
Code example
tsx
1// Legacy (ignored for function components in React 19)2// import PropTypes from "prop-types";3// Price.propTypes = { amount: PropTypes.number.isRequired, currency: PropTypes.oneOf(["USD", "EUR"]) };45// Today: compile-time types with TypeScript6type PriceProps = {7 amount: number;8 currency?: "USD" | "EUR" | "INR";9};1011export function Price({ amount, currency = "USD" }: PriceProps) {12 return <span>{new Intl.NumberFormat("en", { style: "currency", currency }).format(amount)}</span>;13}1415// Runtime validation for untrusted data with Zod16import { z } from "zod";1718const Product = z.object({ id: z.string(), name: z.string(), price: z.number().nonnegative() });19type Product = z.infer<typeof Product>;2021export async function loadProduct(id: string): Promise<Product> {22 const json = await fetch(`/api/products/${id}`).then((r) => r.json());23 return Product.parse(json); // throws if the API returns the wrong shape24}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.