npm i --save react-interval-update
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' });
import { Interval } from 'react-interval-update';
const CurrentTime = () => new Date().toString();
return (
<Interval interval={1000}>
<CurrentTime />
</Interval>
);