Setting Default Prop Values - anastasiamexa/react-complete-guide-course-resources GitHub Wiki

In React, you can define default values for props in a component to ensure that the component still works if certain props are not provided by the parent component. This is useful for making your component more robust and user-friendly. You can set default prop values using the defaultProps property or by using a conditional check within your component.

Here's a basic example:

function Greeting({ name = 'Guest' }) {
  return <div>Hello, {name}!</div>;
}

In this example, if the name prop is not provided when using the Greeting component, it will default to 'Guest'.

⚠️ **GitHub.com Fallback** ⚠️