Component State in React Native Last Updated : 30 Apr, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Introduction to React Native How React Native works? There are two types of data that control a component : props : are immutable and are set by the parent and they are fixed throughout the lifetime of a component.state : is mutable. This means that state can be updated in the future while props can't. we can initialize state in the constructor, and then call setState when we want to change it. props v/s state Use props to pass data and settings through the component tree.Never modify this.props inside of a component; consider props immutable.Use props to for event handlers to communicate with child components.Use state for storing simple view state like whether or not drop-down options are visible.Never modify this.state directly, use this.setstate instead. store: A store holds the whole state tree of the application. The only way to change the state inside it is to dispatch an action on it. A store is not a class. It's just an object with a few methods on it and I'll explain about it upcoming articles on React Native. A more explained way to understand the difference between props, state and store on how and where to use these components. Lets take an example to know more about the state: For example, let's say we want to make text that shows/hide the password from the TextInput layout. The "whether the password is hidden or not" changes over time, so that should be kept in state. JavaScript import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native'; export default class GeeksForGeeks extends Component { state: { password: string, isPasswordHidden: boolean, toggleText: string, } constructor(props: Props) { super(props); this.state = { password: '', isPasswordHidden: true, toggleText: 'Show', }; } handleToggle = () => { const { isPasswordHidden } = this.state; if (isPasswordHidden) { this.setState({ isPasswordHidden: false }); this.setState({ toggleText: 'Hide' }); } else { this.setState({ isPasswordHidden: true }); this.setState({ toggleText: 'Show' }); } }; render() { return ( <View style={styles.container}> <TextInput secureTextEntry={this.state.isPasswordHidden} style={{ width: 400, height: 50, backgroundColor: '#212D3B', color: 'white' }} /> <TouchableOpacity onPress={this.handleToggle} > <Text>{this.state.toggleText}</Text> </TouchableOpacity> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', } }); AppRegistry.registerComponent('GeeksForGeeks', () => GeeksForGeeks); Here, We have initialized state in the constructor, and then called setState when we want to update it. We're actually using two states. One for updating the boolean for password is hidden or not and one for the string text of Show/Hide password. After running the application, you will see something like this : JavaScript import React, { Component } from 'react'; import { AppRegistry, Image } from 'react-native'; export default class GeeksForGeeks extends Component { render() { const image = { url: 'https://www.appcoda.com/wp-content/uploads/2015/04/react-native.png' }; return ( <Image source={image} style={{padding: 186, flex: 1, alignSelf: 'center', justifyContent: 'center', resizeMode: 'contain', }}/> ); } } AppRegistry.registerComponent('GeeksForGeeks', () => GeeksForGeeks); Now Here, we're actually fetching the image from the url and displaying it on the app. If you'll notice, now we are just using one link displaying the image. There is no update done by someone else using the app. This is basically called props. Demo after running the application: Comment More infoAdvertise with us K kartik Improve Article Tags : GBlog Similar Reads GeeksforGeeks Practice - Leading Online Coding Platform GeeksforGeeks Practice is an online coding platform designed to help developers and students practice coding online and sharpen their programming skills with the following features. GfG 160: This consists of 160 most popular interview problems organized topic wise and difficulty with with well writt 6 min read 7 Different Ways to Take a Screenshot in Windows 10 Quick Preview to Take Screenshot on Windows 10:-Use the CTRL + PRT SC Keys to take a quick screenshot.Use ALT + PRT SC Keys to take a Screenshot of any application window.Use Windows + Shift + S Keys to access the Xbox Game Bar.Use Snip & Sketch Application as well to take screenshotTaking Scree 7 min read Artificial Neural Networks and its Applications Artificial Neural Networks (ANNs) are computer systems designed to mimic how the human brain processes information. Just like the brain uses neurons to process data and make decisions, ANNs use artificial neurons to analyze data, identify patterns and make predictions. These networks consist of laye 8 min read Top 50 Java Project Ideas For Beginners and Advanced [Update 2025] Java is one of the most popular and versatile programming languages, known for its reliability, security, and platform independence. Developed by James Gosling in 1982, Java is widely used across industries like big data, mobile development, finance, and e-commerce.Building Java projects is an excel 15+ min read Understanding the Confusion Matrix in Machine Learning Confusion matrix is a simple table used to measure how well a classification model is performing. It compares the predictions made by the model with the actual results and shows where the model was right or wrong. This helps you understand where the model is making mistakes so you can improve it. It 8 min read GATE 2025 Syllabus For CSE (Computer Science & Engineering) GATE Exam 2025 Syllabus for CSE - GATE stands for Graduate Aptitude Test in Engineering, an entrance exam conducted each year for getting admission into the most prestigious institutes across the country including IISc Bengaluru, IITs, NITs, IIITs and many others. The GATE authority (IIT Roorkee for 7 min read HTTP Full Form - Hypertext Transfer Protocol HTTP stands for Hypertext Transfer Protocol, and itâs the system that allows communication between web browsers (like Google Chrome or Firefox) and websites. When you visit a website, your browser uses HTTP to send a request to the server hosting that site, and the server sends back the data needed 7 min read Top 50 Plus Networking Interview Questions and Answers for 2024 Networking is defined as connected devices that may exchange data or information and share resources. A computer network connects computers to exchange data via a communication media. Computer networking is the most often asked question at leading organizations such Cisco, Accenture, Uber, Airbnb, G 15+ min read System Design Interview Questions and Answers [2025] In the hiring procedure, system design interviews play a significant role for many tech businesses, particularly those that develop large, reliable software systems. In order to satisfy requirements like scalability, reliability, performance, and maintainability, an extensive plan for the system's a 7 min read Top HR Interview Questions and Answers (2025) HR interviews can be daunting but they donât have to be. The bottom line in most hiring processes entails testing the personality of a candidate for their communication traits and company culture fit. Being at the initial or experienced levels of your career being prepared for commonly asked fresher 15+ min read Like