Skip to content

Instantly share code, notes, and snippets.

@Mayankgupta688
Last active December 23, 2019 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mayankgupta688/a4256b1c9fb4d7b97fa45a4fe14034eb to your computer and use it in GitHub Desktop.
Save Mayankgupta688/a4256b1c9fb4d7b97fa45a4fe14034eb to your computer and use it in GitHub Desktop.
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