T
T
testtoster2020-01-20 10:25:22
React
testtoster, 2020-01-20 10:25:22

How to increase the number?

Tell me how to make it so that when you click on the count button, one is added to the number?

import React from 'react';
import './App.css';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: '',
      count: 0,
    }
  }

  showText = () => {
    console.log('button work');
    this.setState({ text: 'button work' });
  }

  showCount = () => {
    this.setState({ count: '11' });
  }

  render() {
    return (
      <div>
        <button onClick={this.showText}>Push1</button>
        <p>{this.state.text}</p>
        <button onClick={this.showCount}>Count</button>
        <p>{this.state.count}</p>
      </div>
    )
  }
}

export default App;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2020-01-20
@testtoster

import React from 'react';
import './App.css';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: '',
      count: 0,
    }
  }

  showText = () => {
    console.log('button work');
    this.setState({ text: 'button work' });
  }

  showCount = () => {
    this.setState({ count: this.state.count + 1});
  }

  render() {
    return (
      <div>
        <button onClick={this.showText}>Push1</button>
        <p>{this.state.text}</p>
        <button onClick={this.showCount}>Count</button>
        <p>{this.state.count}</p>
      </div>
    )
  }
}

export default App;

(-__-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question