Answers for "state example in react"

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
1

state in react

class BalanceInquiry extends Component {
  constructor(props) {
    super(props);
    this.state = {
      totalIncome: 0,
    };
  }

  render() {
    return <div>totalIncome {this.state.totalIncome}</div>;
  }
}
Posted by: Guest on February-24-2021
0

setting react state with produce immer

//Initialising State
const [filters, setFilters] = useState({});


//Setting State

setFilters((filters) => (
        produce(filters, draftFilters => {
          if (param[0] === 'page') {
            draftFilters.page = parseInt(param[1], 10)
          }
          if (param[0] === 'per_page') {
            draftFilters.perPage = parseInt(param[1], 10)
          }
        })
      ));
Posted by: Guest on May-09-2020

Browse Popular Code Answers by Language