---
# System prepended metadata

title: React state

---

# React state

// React Component First Letter Capital class based or function based
// maximum 80 character in one line
// make more readable
// space with 2 indent
// one function one work, to create accuracy

// Event => event function
// alway give Naming: (function name)Handler, (function name)Handle, (function name)Event

// setState is a Setter function

```javascript=
class Sum extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      firstValue: '',
      work: ''
    }

    this.myDivHandler = this.myDivHandler.bind(this);
  }

  myDivHandler(event) {
    // code
    this.setState({
      firstValue: event.target.value
    })
  }

  render() {
    return (
      <div className="my-div" id="myDiv">
        <input onChange={this.myDivHandler} value={this.state.firstValue} />
        Simple Div
        {this.state.firstValue}
        {/* {getter method} */}
        {console.log('asss')}
        {this.props.fruit}
      </div>
    );
  }
}

ReactDOM.render(<Sum fruit="Apple" />, document.getElementById("#mount"));
```