Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-time-react-hook

rudyhuynh20MIT0.0.7TypeScript support: included

A React hook that makes your component aware of time.

react, react-hooks, useTime, time

readme

useTime react hook

A React hook that makes your component aware of time.

npm install use-time-react-hook -S

Or

yarn add use-time-react-hook

Examples:

  • Refresh data at a latest time range:
import { useTime } from "use-time-react-hook";

const App = () => {
  const [time] = useTime({ range: "last 1 minutes", interval: "1 sec" });

  useEffect(() => {
    refreshData();
  }, [time]);

  return <div>...</div>;
};
  • Just get time: Demo
import { useTime } from "use-time-react-hook";

const Clock = () => {
  const [time] = useTime();

  return <div> Now is ${new Date(time).toString()} </div>;
};