Skip to content

Instantly share code, notes, and snippets.

@davidmaogomezz
Created September 7, 2020 22:48
Show Gist options
  • Save davidmaogomezz/df020650a75ea01d0b2c43bfcd1d2492 to your computer and use it in GitHub Desktop.
Save davidmaogomezz/df020650a75ea01d0b2c43bfcd1d2492 to your computer and use it in GitHub Desktop.
Temporizador React
<div id="root"></div>
const Clock = props => {
const [date, setDate] = React.useState(new Date());
React.useEffect(() => {
var timerID = setInterval( () => tick(), 1000 );
return function cleanup() { clearInterval(timerID) }
});
function tick() {
setDate(new Date());
}
return (
<div>
<h2>Hora actual {date.toLocaleTimeString()}</h2>
</div>
);
}
ReactDOM.render(
<Clock />,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment