Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Passing Data with Props | Section
/
React Fundamentals

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?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  6

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  6
some-alt