React ES6
🚀 React ES6
ES6 introduced powerful JavaScript features that make React code cleaner and easier to write. Most React code today is written using ES6.
🔥 Key ES6 Features Used in React
| ES6 Feature | Why It’s Important in React |
|---|---|
let and const |
For better variable control |
| Arrow Functions | Short syntax, auto-bind this |
| Classes | Used in older React class components |
| Template Literals | For dynamic strings |
| Destructuring | Easy access to props and state |
| Spread/Rest Operator | For merging and copying values |
Modules (import/export) |
Used to import/export components |
1️⃣ let and const
Use const for values that won’t change, and let when they may change.
2️⃣ Arrow Functions
Used a lot in React for components and event handlers.
Example:
Event handler example:
3️⃣ Classes (Used in older React)
Before hooks, many components were created using class.
Now replaced with:
4️⃣ Template Literals
Useful for dynamic text:
5️⃣ Destructuring
Very common with props and state.
Without destructuring:
With destructuring:
6️⃣ Spread Operator (...)
Used for copying or merging objects/arrays — useful in state updates.
Example:
Updating state example:
7️⃣ Modules (import & export)
React splits code into components. ES6 modules make this possible.
Export:
Import:
Named exports:
Import named:
📌 Summary Table
| Feature | Example Use in React |
|---|---|
| Arrow Function | const App = () => <h1>Hello</h1> |
| Destructuring | const { title } = props |
| Spread Operator | setState({ ...state, count: count + 1 }) |
| Modules | import Component from "./Component" |
🎉 You’re Now Ready for Modern React!
Understanding ES6 makes React much easier to read and write.
