Destructuring of Props in ReactJS
Last Updated :
09 Jan, 2025
Destructuring is a simple property that is used to make code much clear and readable, mainly when we pass props in React.
What is Destructuring?
- Destructuring is a characteristic of JavaScript, It is used to take out sections of data from an array or objects, We can assign them to new own variables created by the developer.
- In destructuring, It does not change an array or any object, it makes a copy of the desired object or array element by assigning them in its own new variables, later we can use this new variable in React (class or functional) components.
- It makes the code more clear. When we access the props using this keyword, we have to use this/ this.props throughout the program, but by the use of restructuring, we can discard this/ this.props by assigning them in new variables.
- This is very difficult to monitor props in complex applications, so by assigning these props in new own variables we can make a code more readable.
Advantages of Destructuring
- It makes developer's life easy, by assigning their own variables.
- Nested data is more complex, it takes time to access, but by the use of destructuring, we can access faster of nested data.
- It improves the sustainability, readability of code.
- It helps to cut the amount of code used in an application.
- It trims the number of steps taken to access data properties.
- It provides components with the exact data properties.
- It saves time from iterate over an array of objects multiple times.
- In ReactJS We use multiple times ternary operators inside the render function, without destructuring it looks complex and hard to access them, but by the use of destructuring, we can improve the readability of ternary operators.
How to use Destructuring?
Destructuring props can simplify your code and improve readability. We can use the Destructuring in the following method in React:
1. Using this.props method:
In this example, we are going to simply display some words using destructuring and without destructuring.
Project Structure: It will look like the following.

Destructuring gives access to the use of props in a more readable format and discards the need for props for every property.
Example: This example uses Greet component with multiple props to show prop destructuring in React.
JavaScript
// Filename - App.js
import React from "react";
import Greet from "./component/Greet";
class App extends React.component {
render() {
return (
<div className="App">
<Greet active="KAPIL GARG" activeStatus="CSE" />
</div>
);
}
}
export default App;
Without Destructuring: This example uses props passed by parent components without destructuring.
JavaScript
// Filename - component/Greet.js
import React from "react";
const Greet = (props) => {
return (
<div>
<div className="XYZ">
<h3> {props.active} </h3>
</div>
<div className="PQR">
<h1>{props.activeStatus}</h1>
</div>
</div>
);
};
export default Greet;
Output: Here props are unnecessarily coming again inside the return, so more concise names of these Destructuring properties are used.
Output for Without Destructuring
With Destructuring: This example first destructures the props coming from parent components before using them.
JavaScript
// Filename - component/Greet.js
import React from "react";
const Greet = (props) => {
// Destructuring
const { active, activeStatus } = props;
return (
<div>
<div className="XYZ">
<h3> {active} </h3>
</div>
<div className="PQR">
<h1>{activeStatus}</h1>
</div>
</div>
);
};
export default Greet;
Output:
Output for With Destructuring
There are many times when the value extracted during Destructuring no more exist, then in this condition we can use of default behavior of Destructuring, in this, apply a default value to the newly declared properties of Destructuring
In the following code, the activeObject will be set true if it is undefined in this.props.
Const {active, activeStatus, activeObject = true } = this.props
3. Using the Re-assigning method:
A variable name that is not a copy of the property being destructured may be used. This is achieved by reassigning as shown below.
In the following code, the properties active, activeStatus have been destructured and reassigned as variables named generating, objectMessage.
const { active : generating, activeStatus : objectMessage} = this.props
Summary
Destructuring in React simplifies code by extracting values from props or state, assigning them to variables for clearer and more readable code. Destructuring can be done using hte props, extraction, and reassinging methods. These approaches improve maintainability, reduces redundancy, and enhances the handling of complex, nested data structures in components.
Similar Reads
ReactJS defaultProps
The defaultProps is a feature in React that allows you to specify default values for props. If a parent component does not pass a value for a particular prop, the default value set in defaultProps will be used instead..What is defaultProps?In React, defaultProps is a static property that can be assi
3 min read
ReactJS Methods as Props
In this article, we will learn about props and passing methods as props. We will also discuss how we can use the child components to pass data to parent components using methods as props.What are props?We know that everything in ReactJS is a component and to pass in data to these components, props a
3 min read
Explain the purpose of render() in ReactJS
Render in React JS is a fundamental part of class components. It is used to display the component on the UI returned as HTML or JSX components. The ReactDOM.render() function takes two arguments, HTML code and an HTML element.Purpose of render()React renders HTML to the web page by using a function
2 min read
ReactJS constructor() Method
In React, lifecycle methods help control what happens at different stages of a component's life. The constructor() method is one of the first methods called when a class component is created. It is mainly used to set up the initial state and bind event handlers before the component appears on the sc
4 min read
What Are Props in React?
Props are read-only inputs passed to a React component. They are used to pass dynamic values like strings, arrays, objects, or functions, making components flexible and reusable.JavaScriptfunction Greet(props) { return <h1>Hello, {props.name}!</h1>; } function App() { return <Greet na
3 min read
React.js Blueprint Suggest Props interface
React.js Blueprint Suggest Props interface is a type definition for the props (short for properties) that a React component expects to receive. It is used to specify the types and the required values for the props that a component will accept. The Props interface is defined as an object type with a
3 min read
What is a pure functional component in ReactJS ?
What is a JavaScript function? A JavaScript function is a block of code designed to perform a particular task which is executed when it is called. How React functional components are similar to JavaScript functions? Conceptually, components are like JavaScript functions. Â A functional component is a
3 min read
React.js Blueprint Icon Component Props
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Icon Component provides a way for users to easily render SVG icons in the application. It is used to display icons in our appl
3 min read
How to use PropTypes in a Functional Component in React?
PropTypes is a mechanism provided by React for type-checking props passed to components. It allows developers to specify the expected types of props (such as strings, numbers, arrays, objects, etc.) and whether they are required or optional. PropTypes helps catch bugs early by providing warnings in
2 min read
React Suite <Cascader> Props
React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React suite Cascader Props. A
5 min read