React Native State

 App name:- Test

Component name:- App.js & Home.js

What is State:- State can change and State work internal in component.

---------------------------------------------------- App.js ---------------------------------------------------------------

/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/

import React, { Component } from 'react'
import { View, Text, Button, } from 'react-native';
import Home from './Component/Home'
class App extends Component {
constructor()
{
super();
this.state={
data:"This is state data"
}
}
render()
{
return(
<View>
<Text>Class Component </Text>
<Text>{this.state.data}</Text>
<Button title="Update State" onPress={()=>{this.setState({data:"new Button Data"})}}/>
</View>

)
}
}
export default App;

------------------------------------------  Home.js ------------------------------------------------------------


import React, { Component } from 'react'
import { View, Text, Button, } from 'react-native';

const Home = (props) => {
return(
<View>
<Text>{props.data}</Text>
</View>
)
}
export default Home;

Comments

Popular posts from this blog

React Native FlatList

React Native class component