idev0085 / react-boilerplate

0 stars 0 forks source link

Are default props available in React Native and if yes for what are they used and how are they used ? #113

Open idev0085 opened 2 years ago

idev0085 commented 2 years ago

Yes, default props available in React Native as they are for React, If for an instance we do not pass props value, the component will use the default props value.

import {View, Text} from 'react-native';
class DefaultPropComponent extends Component {
   render() {
       return ( 
           <View>
             <Text> 
              {this.props.name} 
            </Text> 
          </View>
       )
   }
}
Demo.defaultProps = {
   name: 'BOB'
}

export default DefaultPropComponent;