Created
March 1, 2020 16:21
-
-
Save jaccon/934099cd7ed15f04e703c71fb3d5837a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
export default function App() { | |
const [ counter, setCounter] = useState(0); | |
function Incrementar(){ | |
setCounter( counter + 1); | |
return counter; | |
} | |
function Decrementar(){ | |
if(counter <= 0){ | |
alert("Não posso continuar"); | |
} else { | |
setCounter( counter - 1); | |
return counter; | |
} | |
} | |
return ( | |
<> | |
<h1> Contador: {counter} </h1> | |
<button onClick={Incrementar}> Incrementar</button> <br/><br/> | |
<button onClick={Decrementar}> Decrementar</button> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment