Created
September 7, 2020 22:48
-
-
Save davidmaogomezz/df020650a75ea01d0b2c43bfcd1d2492 to your computer and use it in GitHub Desktop.
Temporizador 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
<div id="root"></div> |
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
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