In React Native, buttons are created using the Button
component, and you can handle button presses using the onPress
prop.
import React from 'react';
import { View, Button, Alert } from 'react-native';
const App = () => {
const handlePress = () => {
Alert.alert('Button Pressed', 'You pressed the button!', [
{ text: 'OK', onPress: () => console.log('OK Pressed') }
]);
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button title="Press Me" onPress={handlePress} />
</View>
);
};
export default App;
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex