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:
1functionCourseHeader(props){
2return(
3<headerclassName="course-header">
4<h1>{props.title}</h1>
5<p>{props.author}</p>
6<span>{props.rating} ★</span>
7</header>
8);
9}
With Parameter Destructuring:
1functionCourseHeader({ title, author, rating }){
2return(
3<headerclassName="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:
1exportdefaultfunctionButton({
2 children,
3 variant ='primary',// Defaults to 'primary' if omitted
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}):