Learn Before
Concept

State in React Js

State in React is similar to a private property that is managed by React. Every change in state calls the render method, displaying the new changes in the user interface.

You can define a state in this way:

class Clock extends React.Component { constructor(props) { super(props); // calls parent contructor with props this.state = {date: new Date()}; // define state with initial value } render() { return ( <div> <h1>Hello, world!</h1> <h2>It is {this.state.date.toLocaleTimeString()}.</h2> </div> ); } }

0

1

Updated 2023-02-17

Tags

JavaScript Programming Language

Object-Oriented Programming

Programming Language Paradigms

General programming languages

Computing Sciences