Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created October 2, 2019 12:25
Show Gist options
  • Save alonbardavid/13711d6275b9e2aee78544b88228061c to your computer and use it in GitHub Desktop.
Save alonbardavid/13711d6275b9e2aee78544b88228061c to your computer and use it in GitHub Desktop.
Patterns for deriving state gist3
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