0
0
React Nativemobile~5 mins

Width, height, and flex in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the flex property do in React Native layout?
The flex property tells a component how much space it should take relative to its siblings inside a container. A higher flex value means the component grows more to fill available space.
Click to reveal answer
beginner
How do you set a fixed width and height for a component in React Native?
You set fixed width and height by adding width and height properties in the style, for example: { width: 100, height: 50 } sets the component to 100 units wide and 50 units tall.
Click to reveal answer
beginner
What happens if you set flex: 1 on a component inside a container?
The component will expand to fill all available space in the container, sharing space equally if siblings also have flex: 1.
Click to reveal answer
intermediate
Can you use both fixed width/height and flex on the same component? What happens?
Yes, but fixed width and height take priority. The flex property will only affect the component if width or height is not fixed or set to auto.
Click to reveal answer
beginner
Why is using flex often better than fixed sizes for mobile layouts?
Because mobile screens vary in size, using flex helps components adjust and fill space proportionally, making the app look good on different devices without hardcoded sizes.
Click to reveal answer
In React Native, what does flex: 2 mean compared to flex: 1 on sibling components?
AThe component with <code>flex: 2</code> takes half the space of the one with <code>flex: 1</code>.
BBoth components take equal space regardless of flex values.
CThe component with <code>flex: 2</code> takes twice as much space as the one with <code>flex: 1</code>.
D<code>flex</code> only affects height, not width.
If you want a component to be exactly 150 units wide and 100 units tall, which style should you use?
A{ width: 150, height: 100 }
B{ flexGrow: 150, flexShrink: 100 }
C{ flex: 1 }
D{ flexBasis: 150 }
What is the default value of flex in React Native if not specified?
Aundefined
B1
Cauto
D0
Which property controls how a component grows to fill available space in React Native?
Aheight
Bflex
Cwidth
Dmargin
If a container has two children with styles { flex: 1 } and { flex: 3 }, how is space divided?
AFirst child gets 1/4, second child gets 3/4 of space
BEqual space for both
CFirst child gets 3/4, second child gets 1/4 of space
DSpace division depends on width property
Explain how flex, width, and height work together to control layout in React Native.
Think about how space is shared inside a container.
You got /4 concepts.
    Describe why using flex is important for mobile app layouts compared to fixed sizes.
    Imagine your app on small and large phones.
    You got /4 concepts.