Navigate back to the homepage

React Native State

Infinitbility
Props and State
January 12th, 2021 · 1 min read
React Native State

This Article Part of React Native Tutorial Series want to start from scrach follow below link

https://infinitbility.com/react-native/table-of-contents

today, we learn to manage to react native state.

React Native manage data using state and props. props mean those data, send data to the child component from the parent component but we can discuss props in our next coming tutorial.

state

we are using state to store data and accessible on the whole file. when you store Anything on state then you can use it anywhere you want like functions, send data to the server, etc.

Anything that changes over time is known as state.

setState

setState() method use to store or update data on state.

React Native create state example

below example explain how to create state on react native.

1import React from 'react';
2import { StyleSheet, Text, View } from 'react-native';
3
4export default class App extends React.Component {
5 this.state = {
6 text: 'React Native State Example'
7 }
8 render() {
9 return (
10 <View>
11 <Text> {this.state.text} </Text>
12 </View>
13 );
14 }
15}

React Native update state example

below example explain how to update state on react native.

1import React, { Component } from 'react'
2import { Text, View } from 'react-native'
3
4class App extends Component {
5 state = {
6 text: 'React Native State Example'
7 }
8 updateState = ()this.setState({ text: 'React Native State Example Updated' })
9 render() {
10 return (
11 <View>
12 <Text onPress = {this.updateState}>
13 {this.state.text}
14 </Text>
15 </View>
16 );
17 }
18}
19export default App;

More From React Native Tutorial

Basics

Advances

Error & Issue Solution

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

More articles from Infinitbility

React Native Project Structure

React Native Project Structure

React Native Tutorial - React Native Project Structure

January 9th, 2021 · 4 min read
React Native Environment setup on ubuntu

React Native Environment setup on ubuntu

React Native Tutorial - Environment setup on ubuntu

January 7th, 2021 · 1 min read
© 2021 Infinitbility
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]