Engineering note · React Js
Destructuring Props in Functional Components
By Farah Jokhio Published Updated
When you pass any props to any componenet, as in this example passing name and age as props to Profile component
<Profile name="John Doe" age={30} />
then you can use destructuring to directly extract name and age from the props object in the Profile component.
It makes the code cleaner and more readable by avoiding repetitive props.name and props.age references.
const Profile = ({ name, age }) => (
<div>
<h1>{name}</h1>
<p>Age: {age}</p>
</div>
);
More engineering notes
Optimizing Performance with React.memo
Wrap components in React.memo to avoid unnecessary re-renders.
Custom Hook : Simplify Code with Reusable Logic
The custom hook in React allows to write data-fetching logic once and reuse it across multiple compo...