Skip to content

Instantly share code, notes, and snippets.

@mohanramphp
Created January 9, 2019 08:52
Show Gist options
  • Save mohanramphp/af4f0267f5b1c3c0e726e18019eb2a0b to your computer and use it in GitHub Desktop.
Save mohanramphp/af4f0267f5b1c3c0e726e18019eb2a0b to your computer and use it in GitHub Desktop.
DateTime Component using React hooks
import React, { useState, useEffect } from 'react';
export const DateTime = () => {
const [dateTime, setDateTime] = useState(new Date());
useEffect(() => {
const id = setInterval(() => setDateTime(new Date()), 1000);
return () => {
clearInterval(id);
}
}, []);
return (
<h4>{`${dateTime.toLocaleDateString()} ${dateTime.toLocaleTimeString()}`}</h4>
);
}
@akbar1155
Copy link

OOOOO zo'r ekan lekin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment