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
Destructuring Props and Default Prop Values0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
3.1Functional Components and Declarative UI3.2Component Props and Read-Only Data Flow3.3Destructuring Props and Default Prop Values3.4Passing Children and Composing Components
HomeTutorialsReact.js for BeginnersDestructuring Props and Default Prop Values
Passing Children and Composing Components

Destructuring Props and Default Prop Values

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

1. The Power of Prop Destructuring

In standard JavaScript functions, accessing properties repeatedly through an object parameter (props.title, props.subtitle, props.onClick) creates verbose, repetitive code.

Modern React applications universally leverage ES6 Object Destructuring directly within the component function parameter signature:

Without Destructuring:

1function CourseHeader(props) {
2 return (
3 <header className="course-header">
4 <h1>{props.title}</h1>
5 <p>{props.author}</p>
6 <span>{props.rating} ★</span>
7 </header>
8 );
9}

With Parameter Destructuring:

1function CourseHeader({ title, author, rating }) {
2 return (
3 <header className="course-header">
4 <h1>{title}</h1>
5 <p>{author}</p>
6 <span>{rating} ★</span>
7 </header>
8 );
9}

Destructuring makes the component's contract immediately obvious at a glance: any developer inspecting the function header can immediately see all the props the component expects.

2. Providing Default Prop Values

When building reusable design system components, certain props should have sensible defaults if the consumer fails to provide them.

You can assign ES6 default parameter values directly inside the destructuring pattern:

1export default function Button({
2 children,
3 variant = 'primary', // Defaults to 'primary' if omitted
4 size = 'md', // Defaults to 'md' if omitted
5 disabled = false, // Defaults to false if omitted
6 onClick
7}) {
8 return (
9 <button
10 className={`btn btn-${variant} btn-${size}`}
11 disabled={disabled}
12 onClick={onClick}
13 >
14 {children}
15 </button>
16 );
17}

Usage:

1// Uses defaults: variant='primary', size='md', disabled=false
2<Button onClick={handleSave}>Save</Button>
3 
4// Overrides specific defaults
5<Button variant="danger" size="lg" disabled={isSubmitting}>
6 Delete Account
7</Button>

Note: A default value is applied if the incoming prop is undefined or omitted entirely. If the parent explicitly passes null, the default value is not applied, because null is an intentional value in JavaScript.

3. Rest Props and Prop Spreading

When creating wrapper components (such as a custom <TextInput> or <Card>), you frequently want to extract a few specific props and forward all remaining standard HTML attributes (id, placeholder, aria-*, onFocus) to the underlying element.

You can combine destructuring with the ES6 Rest syntax (...rest) and JSX Spread ({...rest}):

1export default function TextInput({ label, error, ...restProps }) {
2 return (
3 <div className="input-group">
4 {label && <label className="form-label">{label}</label>}
5
6 <input
7 className={`form-input ${error ? 'input-error' : ''}`}
8 {...restProps} // Spreads placeholder, value, onChange, type, disabled, etc.
9 />
10
11 {error && <span className="error-text">{error}</span>}
12 </div>
13 );
14}

Usage:

1<TextInput
2 label="Corporate Email"
3 type="email"
4 placeholder="sumit@mskinstitute.com"
5 autoComplete="email"
6 required
7 error={emailError}
8 value={email}
9 onChange={handleEmailChange}
10/>

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What JavaScript ES6 feature allows extracting specific prop keys directly inside a component's function parameters?
Question 2
In the component function Avatar({ size = 50 }), what value will size receive if the parent calls <Avatar size={undefined} />?
Question 3
What value will size receive if the parent calls <Avatar size={null} /> in the previous question?
Question 4
What does the JSX spread syntax <input {...restProps} /> accomplish?
Question 5
Why is prop destructuring widely considered a best practice in modern React?
Next Lesson

Passing Children and Composing Components

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

Related Lessons

Previous LessonNext Lesson
Component Props and Read-Only Data FlowPassing Children and Composing Components

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 Beginners 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