use-formatted-time
v1.0.1
Published
A React hook for formatting and updating time in human-readable units.
Downloads
14
Maintainers
Readme
useFormattedTime
A React hook to format and dynamically update remaining time in human-readable units (days, hours, minutes).
Installation
npm install use-formatted-timeParameters
initialMinutes (number): The initial time in minutes.
Returns
(string): A string representing the formatted time left, e.g., "1 day 1 hr" or "45 mins".
Usage
Here’s an example of how to use the hook:
import useFormattedTime from "use-formatted-time";
const Timer = () => {
const formattedTime = useFormattedTime(1500); // 1500 minutes = 1 day 1 hr
return <p>Time Remaining: {formattedTime}</p>;
};
export default Timer;
Features
- Automatically decrements the remaining time by 1 minute every minute.
- Formats time intelligently into days, hours, and minutes.
- Stops at 0 minutes to avoid negative values.
License
This package is licensed under the MIT License.
