It means data moves from a parent component down to its child components through props. The parent controls the data, and children receive it to display or use.
Click to reveal answer
beginner
How does a parent component send data to a child component?
By passing data as props when rendering the child component, like <Child data={value} />.
Click to reveal answer
intermediate
Can a child component directly change the parent's data in React?
No. Children cannot directly change parent data. Instead, parents pass functions as props to children so children can request changes.
Click to reveal answer
intermediate
What is a common pattern for a child to update parent state?
The parent passes a function as a prop to the child. The child calls this function with new data, and the parent updates its state.
Click to reveal answer
beginner
Why is one-way data flow important in React?
It keeps data predictable and easier to debug because data only flows down from parent to child, avoiding unexpected changes.
Click to reveal answer
How does a parent component pass data to a child in React?
AUsing props
BUsing state inside the child
CUsing direct variable assignment
DUsing child’s setState
✗ Incorrect
Parents pass data to children using props, which are like parameters for components.
Can a child component directly modify the parent's state?
AYes, by calling setState on the parent
BNo, children cannot directly modify parent state
CYes, by changing props
DYes, by using context
✗ Incorrect
Children cannot directly change parent state; they can only request changes via functions passed as props.
What is the purpose of passing a function from parent to child as a prop?
ATo pass data from child to parent automatically
BTo let the child read the parent's state
CTo allow the child to update the parent's state
DTo style the child component
✗ Incorrect
Passing a function lets the child call it to ask the parent to update its state.
Which direction does data flow in React's parent-child relationship?
ANo data flow
BFrom child to parent
CBoth directions automatically
DFrom parent to child
✗ Incorrect
Data flows one-way from parent to child via props.
Why is one-way data flow helpful in React?
AIt keeps data predictable and easier to debug
BIt allows children to change parent data directly
CIt makes data unpredictable
DIt prevents data from flowing
✗ Incorrect
One-way data flow keeps the app predictable and easier to understand.
Explain how data flows from a parent to a child component in React and how the child can communicate changes back to the parent.
Think about props and callback functions.
You got /6 concepts.
Describe why React uses one-way data flow between parent and child components and how this benefits app development.
Consider predictability and debugging.
You got /5 concepts.
Practice
(1/5)
1. In React, how does a parent component send data to its child component?
easy
A. By importing the child's variables
B. By passing data as props to the child component
C. By using the child's setState method
D. By directly modifying the child's state
Solution
Step 1: Understand data flow in React
React uses one-way data flow where parents send data down to children.
Step 2: Identify how data is passed
Parents pass data to children using props, which are like function arguments.
Final Answer:
By passing data as props to the child component -> Option B
Quick Check:
Parent to child data flow = props [OK]
Hint: Remember: props flow down from parent to child [OK]
Common Mistakes:
Trying to change child's state directly from parent
Using child's setState from parent
Importing child's variables instead of passing props
2. Which of the following is the correct syntax to pass a prop named title with value "Hello" from a parent to a child component Child?
easy
A. <Child>title="Hello"</Child>
B. <Child {title: "Hello"} />
C. <Child title="Hello" />
D. <Child>{title: "Hello"}</Child>
Solution
Step 1: Recall JSX prop syntax
Props are passed as attributes inside the component tag, like HTML attributes.
Step 2: Match correct syntax
The correct way is <Child title="Hello" /> which sets prop title to "Hello".
Final Answer:
<Child title="Hello" /> -> Option C
Quick Check:
Props look like HTML attributes [OK]
Hint: Props look like HTML attributes inside component tags [OK]
Common Mistakes:
Using object syntax inside JSX tags
Placing props inside children instead of attributes
Using curly braces incorrectly for props
3. Given the code below, what will be rendered inside the <Child /> component?
function Parent() {
const message = "Hi there!";
return <Child text={message} />;
}
function Child(props) {
return <h1>{props.text}</h1>;
}
medium
A.
Hi there!
B.
text
C.
{message}
D. Nothing will render
Solution
Step 1: Identify prop passed from Parent
Parent passes prop named text with value "Hi there!" to Child.
Step 2: Check Child rendering
Child renders <h1> with content from props.text, which is "Hi there!".
Final Answer:
<h1>Hi there!</h1> -> Option A
Quick Check:
props.text = "Hi there!" renders inside <h1> [OK]
Hint: Child renders what parent sends via props [OK]
Common Mistakes:
Confusing prop name with string literal
Expecting variable name to render instead of value
Thinking nothing renders without explicit return
4. What is wrong with the following code that tries to pass data from parent to child?
function Parent() {
const data = "Hello";
return <Child data=data />;
}
function Child(props) {
return <div>{props.data}</div>;
}
medium
A. Parent should use state instead of variable
B. Child component cannot receive props named data
C. Child must destructure props before use
D. The prop value should be inside curly braces: data={data}
Solution
Step 1: Check JSX prop syntax
In JSX, to pass a JavaScript variable as prop value, use curly braces.
Step 2: Identify error in code
Code uses data=data without braces, so it passes string "data" instead of variable value.
Final Answer:
The prop value should be inside curly braces: data={data} -> Option D
Quick Check:
JSX props need curly braces for variables [OK]
Hint: Use curly braces to pass variables as props [OK]
Common Mistakes:
Omitting curly braces around variables in JSX props
Thinking child cannot receive certain prop names
Believing state is required to pass props
5. You want to pass a list of items from a parent to a child component and render them as a list. Which approach correctly implements this parent-child data flow?