Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Passing Data with Props | Reusable Components and Data Flow
Introduction to React

bookPassing Data with Props

Components often need to display different data depending on where they are used. In React, data is passed into components using props. Props are inputs to a component. They allow you to send data from a parent component to a child component and control what the component displays.

Instead of hardcoding values inside a component, props make components reusable. The same component can be used multiple times with different data, producing different UI output.

Below is a simple example of passing data to a component using props:

function Greeting(props) {
  return <h2>Hello, {props.name}</h2>;
}

function App() {
  return <Greeting name="Olivia" />;
}

In this example, the App component passes the value "Olivia" to the Greeting component using a prop called name. The Greeting component receives this data and displays it in the UI.

Note
Note

Props are read-only. A component should not change the props it receives. Their purpose is to control how a component looks or behaves based on external data.

question mark

What are props used for in React?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookPassing Data with Props

Swipe to show menu

Components often need to display different data depending on where they are used. In React, data is passed into components using props. Props are inputs to a component. They allow you to send data from a parent component to a child component and control what the component displays.

Instead of hardcoding values inside a component, props make components reusable. The same component can be used multiple times with different data, producing different UI output.

Below is a simple example of passing data to a component using props:

function Greeting(props) {
  return <h2>Hello, {props.name}</h2>;
}

function App() {
  return <Greeting name="Olivia" />;
}

In this example, the App component passes the value "Olivia" to the Greeting component using a prop called name. The Greeting component receives this data and displays it in the UI.

Note
Note

Props are read-only. A component should not change the props it receives. Their purpose is to control how a component looks or behaves based on external data.

question mark

What are props used for in React?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1
some-alt