State in React Native

  • Use state is used to update any value or state in the code.

  • If we write Swastik in the string and we want to change the string when we will click the button that time we use state.

  • ex: import { StyleSheet, Text, View, Button } from 'react-native' import React, { useState } from 'react' const App = () => { const [name, setName] = useState("Rajesh"); function myname(){ setName("Swastik") } return ( <View> <Text>{name}</Text> <Button title="Press" onPress={myname}/> </View> ) } export default App const styles = StyleSheet.create({})