React Native is a JavaScript framework to build mobile applications which are supported by both Android as well as the iOS platform. React Native apps are coded just once and are available for both the platforms, which helps to save the development time.
To know more about React Native setup for Android, visit my other article from the below link.
In this article, we are going to learn what state and props are and how to use these. There are two types of data in React Native which control component -
- State
- Props
State
State is internal to a component in React Native that is used to keep track of the information.
- State is mutable
- Used within the component (limited to current component)
- Initialize within constructor
- Used “this.setState” to update object.
- Can get initialize from parent component but cannot be changed from a parent component
- Can set initialize the value for child component and cannot be changed in the child component
- Can set default values inside component and can be changed inside component.
- Examples: - User interaction within component like filling forms, checkboxes, buttons click
state = {myState: 'value'}
Props
Props is the short form for properties and can be referred to something that can be changed dynamically in a component. Here, the component receives props from the parent component.
- Props are Immutable
- Used to passed data from parent to child.
- Used to pass data as well as callback functions as props.
- Can get initialize from parent component and can be changed from a parent component
- Can set initialize the value for child component and can be changed in the child component
- Can set default values inside component and can be changed inside component
- Examples :- Used child component in the parent component.
props.myState
Example
Before starting the coding part, we are removing the extra line of code from the App.js file and making it simple so that we easily target React Native state and props.
Note
In this example, I am using Windows 10 and targeting Android application, not iOS application. So, if you are using this code for iOS, the output for iOS might be different in look.
Change App.js file code like below and refresh the screen.
- import React, { Component } from "react";
- import { View, Text } from "react-native";
- class App extends Component {
- render() {
- return (
- <View>
- <Text style={{ fontSize: 40, color: "blue" }}>Hi React Native</Text>
- </View>
- );
- }
- }
- export default App;
O/P
the output should be like below.

Note
Press “control + m” button on the keyboard and select the "Reload" option to refresh the screen or to check output after changes in the code.

Example for State
In the below example, I have added myName variable and assigned value as 'Hi React Native Android' and printed that value using React Native state using syntax {this.state.myName}
- import React, { Component } from "react";
- import { View, Text} from "react-native";
- class App extends Component {
- constructor() {
- super()
- this.state = {
- myName: 'Hi React Native Android'
- }
- }
- render() {
- return (
- <View>
- <Text style={{ fontSize: 40, color: "blue" }}>{this.state.myName}</Text>
- </View>
- );
- }
- }
- export default App;
O/P
The output should be like below.

To change state value
I have added a “Button” from React Native to change the value of state. By using the user-defined handleChange function, I have updated/changed state variable value.
Button





Join the conversation! Your thoughts help the community grow.