Challenge - 5 Problems
Children Prop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will this component render?
Consider this React Native component using the children prop. What will be displayed on the screen?
React Native
const Box = ({ children }) => {
return (
<View style={{ padding: 10, backgroundColor: '#eee' }}>
{children}
</View>
);
};
const App = () => {
return (
<Box>
<Text>Hello</Text>
<Text>World</Text>
</Box>
);
};Attempts:
2 left
💡 Hint
Remember that children can be multiple React elements and are rendered inside the parent.
✗ Incorrect
The Box component renders its children inside a View. Since two Text components are passed as children, both appear stacked vertically.
🧠 Conceptual
intermediate1:30remaining
What type is the children prop in React Native?
In React Native, what is the correct type of the children prop when defining a functional component?
Attempts:
2 left
💡 Hint
Think about what JSX elements you can pass between component tags.
✗ Incorrect
The children prop can be a single React element, multiple elements as an array, or even null/undefined if no children are passed.
❓ lifecycle
advanced2:00remaining
When are children rendered in React Native components?
At what point in the component lifecycle are the children props rendered inside a React Native functional component?
Attempts:
2 left
💡 Hint
Functional components render children as part of their return JSX.
✗ Incorrect
In functional components, children are rendered during the render phase when the component function executes and returns JSX.
📝 Syntax
advanced2:00remaining
Which code correctly passes children to a custom component?
Choose the correct way to pass children to a custom React Native component named Container.
React Native
const Container = ({ children }) => <View>{children}</View>;Attempts:
2 left
💡 Hint
Children are passed between opening and closing tags, not as a prop named children.
✗ Incorrect
Option C correctly uses JSX children syntax. Option C passes children as a prop but is less common and can cause issues. Option C is invalid JSX. Option C has mismatched tags causing syntax error.
🔧 Debug
expert2:30remaining
Why does this component not render its children?
Given the code below, why are the children not visible on screen?
React Native
const Wrapper = ({ children }) => {
return <View />;
};
const App = () => {
return (
<Wrapper>
<Text>Hidden</Text>
</Wrapper>
);
};Attempts:
2 left
💡 Hint
Check what Wrapper returns in its JSX.
✗ Incorrect
Wrapper returns an empty View without including {children}, so children are not rendered.