Here's how you can create a simple React component that displays the current time and a button to update it using Tailwind CSS. This answer assumes that you have installed both React and Tailwind CSS in your project.
673 chars28 lines
In this component, we use the useState
hook to keep track of the current time in the currentTime
state variable. We display the current time using toLocaleTimeString()
method of the Date
object.
When the user clicks the "Update Time" button, we call the handleUpdateClick
function, which sets the currentTime
variable to a new Date
object.
We use Tailwind CSS classes to style the component. The outer div
has a yellow background color (bg-yellow-500
), rounded corners (rounded-lg
), and padding (p-5
) to give it a similar look to the yellow pages.
The h1
tag that displays the current time has a large font size (text-3xl
), bold font weight (font-bold
), and some bottom margin (mb-2
).
Finally, the button has a white background color (bg-white
), gray border (border-gray-400
), and some shadow (shadow
) to make it stand out. When the user hovers over the button, it gets a lighter gray background color (hover:bg-gray-100
) to indicate that it's clickable.
gistlibby LogSnag