Props in React Native

 1) How to use props in React Native

Props:- Props means we can say properties that we receive in an object (prop) from another component or class. Props are usually used to pass data from one component to another component.

App.js

This is the main file to show in UI

import React, {Componentfrom 'react';  
import { TextViewButton } from 'react-native';  
import Propsexample from './PropExample';  //here we are importing the component
export default function PropExample(){
        return (  
            <View style={{
              flex:1,
              justifyContent:'center',
              alignItems:'center',
            }}>  
                <Text style={{
                  fontSize:40,
                  marginVertical:20,
                  textAlign:'center'
                }}>This is props example </Text>
                {/* see below we are passing name="vinod desai" to the Propsexample Component */}
                <Propsexample name='Vinod'/> 
            </View>  
        );  
}  

PropExample.js

import React from 'react';
import {ViewTextfrom 'react-native';

export default function Propsexample(props){
    return(
        <View>
            <Text style={{
                fontSize:30,
                textAlign:'center'
            }}>{props.name}</Text>
            {/* See above line here we are receiving the props which we are used in App.js */}
        </View>
    )
}

This is another component


OUTPUT:




Comments

Popular posts from this blog

Button in React-Native

StyleSheet in React Native

State in React Native