Skip to content

Instantly share code, notes, and snippets.

@juniorUsca
Created March 31, 2021 00:15
Show Gist options
  • Save juniorUsca/ee7ab59a1172021deb791bfa6db9b86b to your computer and use it in GitHub Desktop.
Save juniorUsca/ee7ab59a1172021deb791bfa6db9b86b to your computer and use it in GitHub Desktop.
import React from 'react'
import ReactDOM from 'react-dom'
import { useState } from 'react'
const App = () => {
const [ contador, setContador ] = useState({
izquierda: 0,
derecha: 0,
})
const [ valores, setValores ] = useState([])
const handleClickIzquierda = () => {
setContador({
...contador,
izquierda: contador.izquierda + 1,
})
setValores([
...valores,
'I',
])
}
const handleClickDer = () => {
setContador({
...contador,
derecha: contador.derecha + 1,
})
setValores([
...valores,
'D',
])
}
return (
<div>
<p>Izquierda {contador.izquierda}</p>
<button onClick={handleClickIzquierda} >Click me!</button>
<button onClick={handleClickDer} >Click me!</button>
<p>Derecha {contador.derecha}</p>
{/* {valores.map((e) => { */}
{/* return (<span style={{margin: 8}}>{e}</span>) */}
{/* })} */}
{valores.map((e) =>
<span style={{margin: 8}}>{e}</span>
)}
</div>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment