React ES6 Destructuring

⚛️ React ES6 Destructuring

Destructuring in JavaScript ES6 allows you to extract values from arrays or objects and assign them to variables in a cleaner and shorter way.

React uses destructuring a lot, especially with props, state, and hooks.


✅ Destructuring Objects

Without Destructuring:


 

With Destructuring:


 


🧩 Destructuring in React Props

Without Destructuring:


With Destructuring:


✔ Cleaner and easier to read!


📦 Destructuring Arrays

Useful for React Hooks.

Example:


 


🪝 Destructuring in React Hooks

React hooks return arrays, so destructuring is required.

Example:


 

Here:

  • count → state value

  • setCount → function to update it


🧠 Destructuring with Default Values


 


🧩 Nested Destructuring


 


🚀 Summary

Feature Without Destructuring With Destructuring
Props props.name name
Arrays arr[0] [first]
Hooks Hard to read Cleaner & standard
React Components Verbose Modern style

You may also like...