Skip to content

Things I Learned About React Reusable Components

Posted on:November 22, 2023 at 12:00 AM

How to pass unhandled props to child components in React?

Pass the unhandled props to the rendered element using spread syntax:

const Button = ({ label, ...props }) => <button {...props}>{label}</button>;

This allows extending the reusable component with additional props.

References:

What are some ways to compose reusable React components?

References:

How to handle data fetching in reusable React components?

Split component into a container for data fetching and a presentational component.

The container fetches data and passes it to presentational component as props.

References: