React con eventos

import React, { Component } from 'react'

class Counter extends React.Component {
  constructor(){
    super()
    this.state = {
      value: 0
    };
  }
  
  incrementar = () => {
    this.setState({value:this.state.value+1})
  };
  decrementar = () => {
    this.setState({value:this.state.value-1})
  };
  render() {
    return (
      <div>
        <h2>{this.state.value}</h2>
        <button onClick={this.decrementar}>Decrementar</button>
        <button onClick={this.incrementar}>Incrementar</button>
      </div>
    );
  }
}

export default function App() {
  return <Counter />;
}

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos