What are Props in React?


Why Use Props?

  1. Data Sharing: To share data between components (especially parent to child).
  2. Dynamic UI: To render dynamic content based on data passed from a parent component.
  3. Reusable Components: Create components that can handle different data inputs without rewriting the component logic.

How to Use Props in React?

Step-by-Step Explanation:

1. Passing Props

Props are passed to a child component as attributes in the parent component.

function ParentComponent() {
  return <ChildComponent name="Dampi" age={18} />;
}

In this example:

2. Receiving Props in the Child Component