MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Typing Functional Components and Props in TypeScript0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
9.1Typing Functional Components and Props in TypeScript9.2Typing React Hooks, Generics, and Refs9.3Typing Synthetic Events and Form Elements9.4Polymorphic Component Typing with As and ComponentPropsWithoutRef
HomeTutorialsReact.js for AdvancedTyping Functional Components and Props in TypeScript
Typing React Hooks, Generics, and Refs

Typing Functional Components and Props in TypeScript

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

TypeScript is the foundation of enterprise React development. Typing functional components and their props guarantees compile-time type safety, eliminates undefined is not a function runtime errors, and provides rich autocompletion across design systems.


1. Modern Component Typing: Direct Interface vs React.FC

In early TypeScript React, React.FC (or React.FunctionComponent) was common. However, modern enterprise codebases prefer direct prop typing:

Why React.FC has Fallen Out of Favor

  • In React 17 and earlier, React.FC implicitly injected children: ReactNode into every component, even if the component was a leaf node (like a self-closing badge or button).
  • It complicates generics: <T>(props: Props<T>) is awkward to write with React.FC.
  • Direct function typing is cleaner and mirrors standard TypeScript functions.
1// ✅ Modern Best Practice: Direct Props Typing
2interface UserCardProps {
3 userId: string;
4 name: string;
5 email: string;
6 role?: "admin" | "editor" | "viewer"; // Optional union prop
7 isActive: boolean;
8 onSelect: (id: string) => void; // Typed callback function
9}
10 
11export function UserCard({
12 userId,
13 name,
14 email,
15 role = "viewer", // Default prop value
16 isActive,
17 onSelect,
18}: UserCardProps) {
19 return (
20 <div
21 onClick={() => onSelect(userId)}
22 className={`p-4 rounded-lg border cursor-pointer ${
23 isActive ? "border-cyan-500 bg-cyan-950/20" : "border-slate-800 bg-slate-900"
24 }`}
25 >
26 <h3 className="font-bold text-white">{name}</h3>
27 <p className="text-xs text-slate-400">{email}</p>
28 <span className="inline-block mt-2 px-2 py-0.5 text-xs font-mono uppercase bg-slate-800 text-cyan-400 rounded">
29 {role}
30 </span>
31 </div>
32 );
33}

2. Typing children Explicitly

When a component accepts nested children, define children explicitly using React.ReactNode:

1import React, { ReactNode } from "react";
2 
3interface CardContainerProps {
4 title: string;
5 children: ReactNode; // Accepts JSX elements, strings, numbers, fragments, or null
6 actionSlot?: ReactNode; // Optional slot for buttons or badges
7}
8 
9export function CardContainer({ title, children, actionSlot }: CardContainerProps) {
10 return (
11 <section className="bg-slate-900 border border-slate-800 rounded-xl p-6">
12 <header className="flex justify-between items-center mb-4">
13 <h2 className="text-lg font-bold text-white">{title}</h2>
14 {actionSlot && <div>{actionSlot}</div>}
15 </header>
16 <main className="text-slate-300">{children}</main>
17 </section>
18 );
19}

3. Extending Native HTML Attributes

When building design system primitives (like custom buttons or text fields), extend native HTML attributes so your components accept standard attributes (id, aria-label, disabled, style, className) automatically:

1import React, { ButtonHTMLAttributes } from "react";
2 
3interface CustomButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
4 variant?: "primary" | "secondary" | "danger";
5 isLoading?: boolean;
6}
7 
8export function CustomButton({
9 variant = "primary",
10 isLoading = false,
11 children,
12 className = "",
13 disabled,
14 ...restProps // Forward all standard button attributes (type, onClick, aria-*, etc.)
15}: CustomButtonProps) {
16 const variantStyles = {
17 primary: "bg-cyan-600 hover:bg-cyan-500 text-white",
18 secondary: "bg-slate-800 hover:bg-slate-700 text-slate-200",
19 danger: "bg-rose-600 hover:bg-rose-500 text-white",
20 };
21 
22 return (
23 <button
24 disabled={disabled || isLoading}
25 className={`px-4 py-2 rounded-lg font-medium transition flex items-center justify-center gap-2 disabled:opacity-50 ${variantStyles[variant]} ${className}`}
26 {...restProps}
27 >
28 {isLoading ? (
29 <span className="h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent" />
30 ) : null}
31 {children}
32 </button>
33 );
34}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is direct props typing (function Button(props: ButtonProps)) preferred over React.FC in modern React?
Question 2
What TypeScript type should you use to type children when accepting any valid renderable React content?
Question 3
How do you allow a custom button component to accept all standard native HTML <button> attributes like disabled, type, and onKeyDown?
Question 4
How should an optional callback prop onSelect that receives a string id be typed?
Question 5
What is the benefit of defining union literal types (e.g. role?: "admin" | "editor" | "viewer") over plain string?
Next Lesson

Typing React Hooks, Generics, and Refs

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Memory Profiling and Heap Snapshots in ProductionTyping React Hooks, Generics, and Refs

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext