Last active
December 23, 2019 07:02
-
-
Save Mayankgupta688/a4256b1c9fb4d7b97fa45a4fe14034eb to your computer and use it in GitHub Desktop.
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
function useCustomTimeHooks() { | |
function getCurrentTime() { | |
let date = new Date(); | |
return date.getHours() + ": " + date.getMinutes() + ": " + date.getSeconds(); | |
} | |
let [time, setTime] = useState(getCurrentTime()); | |
setTimeout(() => { | |
setTime(getCurrentTime()); | |
}, 1000); | |
return [time]; | |
} | |
function ApplicationComponent() { | |
const [time] = useCustomTimeHooks(); | |
return ( | |
<div> | |
<h1>Current Time: {time}</h1> | |
</div> | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment