Props
In React Native, most components can be customized when they are created,with different parameters. These created parameters are called as Props. The properties of components are pronounced as Props.
They are immutable, and they cannot be updated. In React Native, data flows in one direction => from the parent to child. Components receive the props from their parent. These props should not be modified inside the component.Presentational components should get all data by passing props. Only container components should have State.
We can also use props in our components. To implement props in our components, 'this.props' is use.
Here is the example to understand more easily.
_______________________________________________________
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
class ChildClass extends Component {
render() {
return (
<View style={{alignItems: 'center'}}>
<Text style={styles.welcome}>Hello {this.props.name}!</Text>
</View>
);
}
}
export default class ParentsClass extends Component {
render() {
return (
<View style={{alignItems: 'center'}}>
<ChildClass name='Pooja' />
<ChildClass name='Nikita' />
<ChildClass name='Arpita' />
</View>
);
}
}
const styles = StyleSheet.create({
welcome: {
fontSize: 25,
color:'red',
}
});
___________________________________________________________________________________
Output: