Answers for "set state from props react"

5

state and props

What is the Props
Props is short for properties and they are used to pass data between React components. React’s data flow between components is uni-directional
wt is State
which allows components to create and manage their own data
Posted by: Guest on November-21-2020
15

State on React class Component

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }

  render() {
    return (
      <div>
        <p>You clicked {this.state.count} times</p>
        <button onClick={() => this.setState({ count: this.state.count + 1 })}>
          Click me
        </button>
      </div>
    );
  }
}
Posted by: Guest on March-13-2020

Browse Popular Code Answers by Language