What's the difference between writing react's state on constructor and writing on the class attribute?

class Test extends Component {
  state = {
    count:1
  }
  constructor(props){
    super(props)
    this.state = {
      count:1
    }
  }
  onClickFn = () => {
    this.setState({
      count:this.state.count+1
    })
  }
  render(){
    return (<div onClick={this.onClickFn}>{this.state.count}</div>)
  }


        <Test />
        <Test />
        <Test />

there should be static properties above and instance properties below, but I don"t feel any different. Who will elaborate on
Writing multiple static attributes without sharing

Mar.31,2021

if it's just a value, of course you can

if you want to set the value and display it, you need the following state


clipboard.png
compare the output of babel, there is no difference at all

Menu