Answers for "react states"

15

state react

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
0

react state

const [stateName, SetStateName] = useState();
SetStateName('any name');
Posted by: Guest on October-08-2021
0

reading state react

<button onClick={() => this.setState({ count: this.state.count + 1 })}>
    Click me
  </button>
Posted by: Guest on March-13-2020
-1

reactjs update state example

You have to use setState() for updating state in React
{
  hasBeenClicked: false,
  currentTheme: 'blue',
}

setState({
	hasBeenClicked: true
});
Posted by: Guest on November-22-2020

Browse Popular Code Answers by Language