Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/filipchalupa/react-use-clock


https://github.com/filipchalupa/react-use-clock

Last synced: about 15 hours ago
JSON representation

Awesome Lists containing this project

README

        

# React useClock [![npm](https://img.shields.io/npm/v/react-use-clock.svg)](https://www.npmjs.com/package/react-use-clock) ![npm type definitions](https://img.shields.io/npm/types/react-use-clock.svg)

Simplified access to current hours, minutes, seconds.

[![screencast](https://raw.githubusercontent.com/FilipChalupa/react-use-clock/HEAD/screencast.gif)](https://react-use-clock.netlify.app)

## Installation

```bash
npm install react-use-clock
```

## How to use

```jsx
import { useClock } from 'react-use-clock'

const MyClockComponent = () => {
const clock = useClock()

return (



Time is:{' '}

{clock.hours.toString().padStart(2, '0')}:
{clock.minutes.toString().padStart(2, '0')}:
{clock.seconds.toString().padStart(2, '0')}



Date is:{' '}

{clock.day}. {clock.month}. {clock.year}



Using formatter:{' '}

{clock.date.toLocaleTimeString('en', {
day: 'numeric',
month: 'long',
year: 'numeric',
})}




)
}
```

Create your own wrapper component. You can get inspired by [Example here](src/stories/Example.tsx) and [Storybook here](https://react-use-clock.netlify.app).

## Development

Run `npm start` and `npm run storybook` parallelly.