Curriculum
Course: Basic Components in React Native
Login

Curriculum

Basic Components in React Native

Text lesson

Lesson 4: Button Component

Introduction: The Button component provides a simple way to handle user interactions by capturing tap events.

 

Using the Button Component:

  • The Button component requires a title and an onPress prop.
  • It is a simple wrapper around the Touchable component.

 

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.

Layer 1
Login Categories
This website uses cookies and asks your personal data to enhance your browsing experience.