Created
October 2, 2019 12:25
-
-
Save alonbardavid/13711d6275b9e2aee78544b88228061c to your computer and use it in GitHub Desktop.
Patterns for deriving state gist3
This file contains hidden or 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
function ticker(){ | |
const [time,setTime] = useState(0); | |
useEffect(()=>{ | |
const intervalId = setInterval(()=>setTime(time+1),1000) | |
return ()=>clearInterval(intervalId) | |
}) | |
return <div> | |
seconds elapsed {time} | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment