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

FeatureWithout DestructuringWith Destructuring
Propsprops.namename
Arraysarr[0][first]
HooksHard to readCleaner & standard
React ComponentsVerboseModern style

You may also like...