Introduction
In the sixth part of my React article series, we are going to learn what is State and how to use it in the React Component. Before moving to components, please read my previous articles.
- React Introduction – Day One
- React Environment Setup – Day Two
- React Fundamentals – Day Three
- Creating And Using React Components – Day Four
- React JSX and Props – Day Five
State
In React, each component has a state. A state is an object with values. It determines a component's rendering and behavior. It is used when a component needs to change independently of its parent. Components with the state have more complexity.

Note - Image Source Google
Defining the state in React component.
- constructor(props) {
- super(props);
- this.state = {
- articleName: "What is State in React?"
- }
- }
Accessing a state via the state property and supplied as attribute.
- <Article articleName={this.state.articleName}/>
As in the above screenshot, we have to pass the props as the attributes in elements, i.e., ‘articleName’.
Following are the steps to use States in React Component
- Create a React application using ‘create-react-app app-name’.
- After creating the application, open the src/App.js file. Paste the following code in that file.
- import React, { Component } from 'react';
- import logo from './logo.svg';
- import './App.css';
- class App extends Component {
- constructor(props) {
- super(props);
- this.state = {
- articleName: "What is Props in React?"
- };
- this.handleClick = this.handleClick.bind(this);
- }
- handleClick(){
- this.setState({
- articleName: "What is State in React?"
- });
- }
- render() {
- return (
- <div className="App">
- <header className="App-header">
- <img src={logo} className="App-logo" alt="logo" />
- <h1 className="App-title">Welcome to C# Corner</h1>
- </header>
- <Article articleName={this.state.articleName}/>
- <Author authorName="Jeetendra"/>
- <button onClick={this.handleClick}> Click to Change State </button>
- </div>
- );
- }
- }
- const Article = (props) =>{
- return(
- <h1 className="App-intro">{props.articleName}</h1>
- );
- }
- class Author extends React.Component {
- render(){
- return(
- <h1 className="App-intro">By {this.props.authorName}</h1>
- );
- }
- }
- export default App;



kalu singh raoPosted Nov 2, 2018, 8:40 AM
Good Job. Thanks
Laxmi narayanaPosted Oct 9, 2018, 7:52 AM
When can i expect next article on react js like redux session..
Jasminder SinghPosted Aug 11, 2018, 7:09 AM
Can you give an example when we should use State and when we should use Props
Hadshana KamalanathanPosted Aug 3, 2018, 10:01 AM
Nice article...
Shrimant TelgavePosted Aug 2, 2018, 11:33 AM
Nice article..............