0
0
React Nativemobile~20 mins

Button and Pressable in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Press Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Button vs Pressable: Which triggers onPress correctly?
Consider the following React Native code snippet. Which option correctly triggers the onPress event when the user taps the component?
React Native
import React from 'react';
import { View, Button, Pressable, Text } from 'react-native';

export default function App() {
  return (
    <View>
      {/* Component here */}
    </View>
  );
}
A<Button title='Click me' onPress={() => alert('Pressed!')} />
B<Pressable><Text>Click me</Text></Pressable>
C<Pressable onPress={() => alert('Pressed!')}><Text>Click me</Text></Pressable>
D<Button title='Click me' />
Attempts:
2 left
💡 Hint
Only components with an onPress handler will respond to taps.
lifecycle
intermediate
2:00remaining
What happens when you press a Pressable with onPressIn and onPressOut?
Given a Pressable component with both onPressIn and onPressOut handlers, what is the correct sequence of events when the user taps and releases the component?
React Native
import React from 'react';
import { Pressable, Text } from 'react-native';

export default function App() {
  return (
    <Pressable
      onPressIn={() => console.log('Pressed In')}
      onPressOut={() => console.log('Pressed Out')}
      onPress={() => console.log('Pressed')}
    >
      <Text>Tap me</Text>
    </Pressable>
  );
}
APressed In → Pressed → Pressed Out
BPressed → Pressed In → Pressed Out
CPressed Out → Pressed In → Pressed
DPressed In → Pressed Out → Pressed
Attempts:
2 left
💡 Hint
Think about the order of touch events: press down, press action, release.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Button usage
Which option contains a syntax error that will prevent the React Native app from compiling?
React Native
import React from 'react';
import { Button } from 'react-native';

export default function App() {
  return (
    <Button title='Press me' onPress={() => alert('Pressed!')} />
  );
}
A<Button title='Press me' onPress={() => alert('Pressed!)}></Button>
B<Button title='Press me' onPress={() => alert('Pressed!')} />
C<Button title='Press me' onPress={() => alert('Pressed!')}></Button>
D<Button title='Press me' onPress={() => alert('Pressed!')}/>
Attempts:
2 left
💡 Hint
Check if all quotes and brackets are properly closed.
🔧 Debug
advanced
2:00remaining
Why does this Pressable not respond to taps?
A developer wrote this code but tapping the Pressable does nothing. What is the cause?
React Native
import React from 'react';
import { Pressable, Text } from 'react-native';

export default function App() {
  return (
    <Pressable>
      <Text>Tap me</Text>
    </Pressable>
  );
}
AText components cannot have onPress handlers.
BPressable requires a style prop to be tappable.
CPressable has no onPress handler, so it does not respond.
DPressable must have a child View component to work.
Attempts:
2 left
💡 Hint
Where is the onPress handler placed?
🧠 Conceptual
expert
2:00remaining
What is the main advantage of Pressable over Button in React Native?
Choose the best explanation for why a developer might prefer Pressable instead of Button for touch interactions.
APressable automatically handles accessibility without extra props.
BPressable allows more customization of touch feedback and styling than Button.
CButton supports more platforms than Pressable.
DButton can only be used inside ScrollView components.
Attempts:
2 left
💡 Hint
Think about flexibility and control over appearance and behavior.