PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

React · Theory

PropTypes in React

← All stacks

Theory

56/94

PropTypes in React

PropTypes is a runtime checker you attach to a function or class: MyComp.propTypes = { … }. isRequired marks must-have props. defaultProps (or default parameters) fill gaps. You import from 'prop-types', not from 'react' (that split happened years ago).

If the team already uses TypeScript, don’t add PropTypes ‘for extra safety’ on every file — you’ll maintain two sources of truth. Pick one.

PropTypes in React — on screen — Pen × 1. Missing qty uses default. Wrong type → dev warning.

Exam tip

prop-types package + isRequired. TS in new code.

Example

// PropTypes + default
import PropTypes from "prop-types";

function Item({ title, qty }) {
  return <li>{title} × {qty}</li>;
}

Item.propTypes = {
  title: PropTypes.string.isRequired,
  qty: PropTypes.number,
};
Item.defaultProps = { qty: 1 };

PropTypes in React — on screen: Pen × 1. Missing qty uses default. Wrong type → dev warning.

Short notes

  • DefRuntime prop checks (dev).
  • Pkg : prop-types.
  • Now : TS usually replaces it.

Questions

1

Explain PropTypes as if you are teaching a junior — definition, then one tiny UI.

2

What does the example show on screen (or print), and what does that prove?

3

What mistake do freshers make with PropTypes?

Previous← React ArchitectureNextBrowserRouter in React →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.