Javatpoint Logo
Javatpoint Logo

React Native State

There are two types of data state and props in React Native which control the component. The component that uses the state is mutable. They can be changed later on if required. The props component is immutable, and it is fixed throughout the lifetime.

The state is generally initialized in constructor and then call setState when we want to change it.

React Native state Example 1

In this example, we create a Text component with state data. The content of Text component will be updated by clicking on it. The event onPress call the setState, and it updates the state "myState" text.


React Native State React Native State

React Native state Example 2

Let's create another example of state data in which we interchange the Text value "Show" and "Hide" to show and hide the input password.

Create three state variables that will be changed by clicking the Text component defined as a state. Clicking the Text component calls the handleToggle function, and the current state of Boolean variable "isPasswordVisible" is assigned in it. Here, if the condition checks the value of "isPasswordVisible" and proceeds accordingly.


React Native State React Native State
Next TopicReact Native Props

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA