0 day streak
javascript / beginner
Snippet

Object Destructuring

Destructuring allows you to unpack properties from objects into distinct variables. This makes your React components much cleaner and easier to read compared to repetitive 'user.name' calls.

snippet.js
javascript
1
2
3
4
5
6
7
8
9
const UserProfile = ({ user }) => {
const { name, email, age } = user;
return (
<div>
<h2>{name}</h2>
<p>{email}</p>
</div>
);
};
react
Breakdown
1
const { name, email, age } = user;
Extracts 'name', 'email', and 'age' from the 'user' object in one line.