0
0
Reactframework~10 mins

Passing props to components in React - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Passing props to components
Parent Component
Define props values
Render Child Component with props
Child Component receives props
Child uses props to render output
The parent component defines values and passes them as props to the child component, which then uses these props to display content.
Execution Sample
React
function Greeting(props) {
  return <h1>Hello, {props.name}!</h1>;
}

function App() {
  return <Greeting name="Alice" />;
}
This code passes the name 'Alice' as a prop to the Greeting component, which displays a personalized message.
Execution Table
StepActionProps PassedChild Output
1App renders Greetingname: 'Alice'Hello, Alice!
2Greeting receives propsname: 'Alice'Hello, Alice!
3Greeting returns JSXname: 'Alice'<h1>Hello, Alice!</h1>
4React renders output to DOMname: 'Alice'Visible: Hello, Alice!
💡 Rendering completes after Greeting returns JSX and React updates the DOM.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
props.nameundefinedAliceAliceAlice
Key Moments - 2 Insights
Why does Greeting receive props with the name 'Alice'?
Because in step 1, App passes the prop name='Alice' when rendering Greeting, as shown in the execution_table row 1.
What happens if we don't pass a prop to Greeting?
Greeting.props.name would be undefined, so the output would show 'Hello, !' as no name is provided, similar to the initial 'Start' state in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the value of props.name inside Greeting?
A"Alice"
Bundefined
Cnull
D"Greeting"
💡 Hint
Check the 'Props Passed' column at step 2 in the execution_table.
At which step does React update the DOM with the greeting message?
AStep 1
BStep 4
CStep 3
DStep 2
💡 Hint
Look for the step where the output becomes visible in the execution_table.
If App passed name="Bob" instead of "Alice", what would props.name be at step 2?
Aundefined
B"Alice"
C"Bob"
Dnull
💡 Hint
Refer to how props are passed from App to Greeting in the execution_table step 1.
Concept Snapshot
Passing props to components:
- Parent sends data as props: <Child propName="value" />
- Child receives props as function argument
- Use props inside child: props.propName
- Props are read-only inside child
- Enables reusable, dynamic components
Full Transcript
In React, components can receive data from their parent components through props. The parent component includes the child component in its JSX and passes values as attributes. These values become properties (props) accessible inside the child component as an object. The child uses these props to render dynamic content. For example, a Greeting component can receive a name prop and display a personalized message. The execution flow starts with the parent rendering the child with props, the child receiving and using the props, and finally React rendering the output to the screen. Props are immutable inside the child, meaning the child should not change them. This pattern helps build reusable and flexible components.