Introduction: The Button component provides a simple way to handle user interactions by capturing tap events.
Using the Button Component:
title
and an onPress
prop.
Example Code:
import React from 'react';
import { View, Button, Alert, StyleSheet } from 'react-native';
const App = () => {
return (
<View style={styles.container}>
<Button
title="Press me"
onPress={() => Alert.alert('Button pressed!')}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default App;
Conclusion: The Button component is straightforward but powerful for handling user interactions. Mastering its use is key to creating interactive applications.