Skip to content

pikselpalette/react-interval-update

Repository files navigation

React Interval Update

License

Installation

npm i --save react-interval-update

Usage

As a HOC

import { withInterval } from 'react-interval-update';

const CurrentTimeWithUpdater = ({ onIntervalChange, interval }) => (
  <div>
    {new Date().toString()}
    <br />
    Update interval:
    <input
      value={interval}
      onChange={({ target }) => onIntervalChange(parseInt(target.value, 10))}
    />
  </div>
);

export default withInterval(CurrentTimeWithUpdater, { interval: 5000, prop: 'update' });

As a component

import { Interval } from 'react-interval-update';

const CurrentTime = () => new Date().toString();

return (
  <Interval interval={1000}>
    <CurrentTime />
  </Interval>
);

About

Re-render a component at every interval

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published