Default Props for Components


This code sets a default value for the text prop in the Button component. If no text prop is provided when using the component, it will default to "Click me". This helps avoid undefined values and makes the component more user-friendly.

const Button = ({ text = "Click me" }) => <button>{text}</button>;

You Might Also Like

Simplify Context Usage with a Custom Hook

Instead of using useContext directly every time, create a custom hook: **1. Define the Context and...

How to Use Error Boundaries to Handle Errors

## 1. Define an ErrorBoundary class component ``` class ErrorBoundary extends React.Component { //...