26
loading...
This website collects cookies to deliver better user experience
Object
where we store our values that belongs to the Component.variables
, they are the containers which used to store the data values.const car =
{
color:"Red",
Model:"3",
Name:"Tesla"
}
props
then why we need the State.
It’s helps in making the Dynamic Web Application.
Also we need something which keep track what is happing in our Application.
State is Designed to Change in Response to the Event.
read more
and the text expands this is also a state change.UI Logic → When we are changing the State of the Interface
Like, we click on some button and a pop-up opens so this comes under the UI logic.
Business Logic → When we are changing the state of the Data.
Like, we are Deleting some message.
this.state
same as the this.props
it will return a object which will have the key-value pairs.**if u did like this
{this.state} -> this will give the error
but if we do like
{this.props} -> this will not give any error if there is nothing in that it is not
rendered.**
constructor(props){
super(props);
this.state={
score:0
}
}
props
as an argument after that we have call the Super with props as Argument class Component{
constructor(){
console.log('Inside Constructor of Component');
}
}
class App extends Component{
constructor(){
console.log('Inside the Constructor of App');
}
}
const x = new App();
Super
to use the functionality of the derived class.class ScoreKeeper extends React.Component{
constrctor{
super();
this.state={
name=**this.props.name**
}
}
render(){
return (
<h1>Score : {this.state.score}</h1>
)
}
}
**super(props)
;**class ScoreKeeper extends React.Component{
state={
score:0
}
render(){
return (
<h1>Score : {this.state.score}</h1>
)
}
}
state={
score:0
}
this.state = {num:0};
this.state = {num:99};
**Don't do like this to change the state**
import React, { Component } from 'react'
class Random extends Component {
constructor(props){
super(props);
this.state={num:0}
this.maketimer();
}
maketimer()
{
setInterval(() => {
let rand = Math.floor(Math.random()*this.props.maxNum)
this.setState({num:rand});
}, 1000);
}
render(){
return(
<h1>{this.state.num}</h1>
)
}
}
export default Random;