A configurable timer utility to pass time props to your components via Context API at a set interval.
yarn add @quiqupltd/react-time-provider
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>
)
}
prop | Type | Description | Default |
---|---|---|---|
now | Number | UNIX timestamp ie. 1523444679818 |
Date.now() |
isTimerRunning | Boolean | true or false starts or stops the timer |
false |
timerInterval | Number | interval length in milliseconds | 1000 |
Children of TimeConsumer
will have access to TimeProvider
's props via render props
MIT © Quiqup