NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 5

Basics of View, Text and Button UI example in react native

In this example:

  1. We import the necessary components from 'react-native'.
  2. We define a functional component App that returns a View containing a Text component and a Button component.
  3. We use StyleSheet to define styles for our components.
  4. We define a handlePress function that gets called when the button is pressed. For now, it just logs a message to the console.

Here's is the Code !!

import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';

const App = () => {
  const handlePress = () => {
    console.log('Button pressed!');
  };

  return (
    <View style={styles.container}>
      <Text style={styles.text}>Hello, React Native!</Text>
      <Button title="Press Me" onPress={handlePress} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  text: {
    fontSize: 24,
    marginBottom: 20,
  },
});

export default App;

Chapter 4

React native app file and folder structure.

Previous chapter

Chapter 6

What is JSX in react native

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex