0
0
React Nativemobile~20 mins

Children prop in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Children Prop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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>
  );
};
AOnly one Text component showing 'HelloWorld' concatenated.
BTwo Text components stacked vertically showing 'Hello' and 'World'.
CAn error because multiple children are not allowed.
DNothing is rendered because children prop is ignored.
Attempts:
2 left
💡 Hint
Remember that children can be multiple React elements and are rendered inside the parent.
🧠 Conceptual
intermediate
1: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?
AA boolean indicating if children exist.
BOnly a string value.
CA number representing the count of child elements.
DA single React element or an array of React elements.
Attempts:
2 left
💡 Hint
Think about what JSX elements you can pass between component tags.
lifecycle
advanced
2: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?
ADuring the render phase, when the component function is called.
BOnly after the componentDidMount lifecycle method.
CBefore the component function is called.
DAfter the component unmounts.
Attempts:
2 left
💡 Hint
Functional components render children as part of their return JSX.
📝 Syntax
advanced
2: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>;
A<Container children={<Text>Hi</Text>} />
B<Container><Text>Hi</Text></Text></Container>
C<Container><Text>Hi</Text></Container>
D<Container>{Text('Hi')}</Container>
Attempts:
2 left
💡 Hint
Children are passed between opening and closing tags, not as a prop named children.
🔧 Debug
expert
2: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>
  );
};
AWrapper does not render the children inside its View.
BText component is invalid inside Wrapper.
CChildren prop is undefined by default.
DView component cannot have children.
Attempts:
2 left
💡 Hint
Check what Wrapper returns in its JSX.