0.0.1 • Published 6 years ago

@quiqupltd/react-time-provider v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

React TimeProvider and TimeConsumer

NPM Build Status Test Coverage JavaScript Style Guide Documentation Status

A configurable timer utility to pass time props to your components via Context API at a set interval.

Install

yarn add @quiqupltd/react-time-provider

Use

import React, { Component } from 'react'
import TimeProvider from '@quiqupltd/react-time-provider'

class App extends Component {
  render() {
    return (
      <TimeProvider isTimerRunning={true}>
        <Routes />
      </TimeProvider>
    )
  }
}

Then consume in your app

import { TimeConsumer } from '@quiqupltd/react-time-provider'

const RemainingTime = () => {
  return (
    <TimeConsumer>
      { ({now}) => <ComponentThatNeedsTimer now={now}/> }
    </TimeConsumer>
  )
}

TimeProvider

propTypeDescriptionDefault
nowNumberUNIX timestamp ie. 1523444679818Date.now()
isTimerRunningBooleantrue or false starts or stops the timerfalse
timerIntervalNumberinterval length in milliseconds1000

TimeConsumer

Children of TimeConsumer will have access to TimeProvider's props via render props

License

MIT © QuiqupQuiqup