day-time-greet
v1.0.6
Published
A simple and easy-to-use library for greeting users with appropriate messages for 'good morning,' 'good evening,' and 'good night' based on the time of day
Downloads
37
Maintainers
Readme
Welcome to day-time-greet
A simple and easy-to-use library for greeting users with appropriate messages for 'good morning,' 'good evening,' and 'good night' based on the time of day
useTime Hook
A custom React hook to get a greeting message based on the time of day.
Installation
npm install day-time-greet
example for react.js
import React from "react";
import { useTime } from "day-time-greet";
function App() {
const { time } = useTime();
console.log(time); // Good morning, Good afternoon, or Good evening
return (
<div>
<h1>{time}</h1>
</div>
);
}
export default App;
example for vanilla js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vanilla JavaScript Example</title>
</head>
<body>
<div id="time-display"></div>
<script src="./path/to/day-time-greet.js"></script>
<script>
function updateTime() {
const { time } = useTime();
console.log(time); // Good morning, Good afternoon, or Good evening
document.getElementById("time-display").innerText = time;
}
// Call updateTime function periodically to update the time display
setInterval(updateTime, 1000);
</script>
</body>
</html>