React Native Development concepts - State

React Native Development concepts - State

React Native State

State is the main attribute of react native which is mutable in nature(which means its values can be changed inside the component), it gives a powerful mechanism to manage the data available inside any component from start to end of the component life cycle (state is object containing all the data required to create component combining with UI elements), in case of any change in the state render function get executed (which means if some change happens to an state variable or object render function get called to show the required changes), in general, all the state get initialize inside the constructor function.

  • The state is an object and will be initialized inside our component.

  • On the loading of any component, first, it will check for the initialized value.

  • With the help of this keyword, we can access the value of any state data, like this.state.data

  • If there will be any change in any attribute of the state data then render function will be executed.

Advantages of using State​​​​​​​

  • States are like global variables for any component so they are available everywhere inside the given components which can be used for many purposes.

  • Because the state is managed by react itself, memory management is being taken care of very well in this case.

  • The state is private for the component and can be mutable inside component. Because it is private inside component states are secure inside any components.