Engineering note · React Js

Destructuring Props in Functional Components

By Published Updated

React Js

When you pass any props to any componenet, as in this example passing name and age as props to Profile component

CODE SAMPLE Code snippet
<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.

CODE SAMPLE Code snippet
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...