Created
June 11, 2020 02:34
-
-
Save wwiechorek/026cd6ee903933eaedeeb0af22ce8db1 to your computer and use it in GitHub Desktop.
Erro React
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, { useEffect, useState, useCallback } from 'react' | |
function App() { | |
const [user, setUser] = useState(false) | |
const [count, setCount] = useState(0) | |
const valid = useCallback(() => { | |
console.log(count) | |
if(count === 12) { | |
alert("12") | |
} | |
}, [count]) | |
const counter = useCallback(() => { | |
setCount(c => c + 1) | |
valid() | |
}, [valid]) | |
const init = useCallback(() => { | |
console.log("Init: ", user) | |
setInterval(counter, 1000) | |
}, [user, counter]) | |
useEffect(() => { | |
if(user === true) { | |
init() | |
} | |
}, [user, init]) | |
return ( | |
<div> | |
<button onClick={() => setUser(true)}>Entrar</button> | |
<button onClick={() => setCount(10)}>Count = 10</button> | |
{count} | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment