0 day streak
javascript / beginner
Snippet

Destructuring Props in Components

Instead of using 'props.name', you can extract values directly in the function signature using curly braces. This makes the code cleaner and more readable.

snippet.js
javascript
1
2
3
function WelcomeBanner({ username, level }) {
return <h1>Welcome back, {username}! Level: {level}</h1>;
}
react
Breakdown
1
{ username, level }
Destructures the props object to get individual variables immediately.
2
{username}
Uses the extracted variable directly without the 'props.' prefix.