react-timer-hoc
react-timer-hoc copied to clipboard
Use of setDelay causing multiple timer updates
import React from 'react'
import ReactDOM from 'react-dom'
import reactTimer from 'react-timer-hoc'
class Timer extends React.Component
{
componentDidMount()
{
this.props.timer.setDelay(this.props.timerTick);
}
componentDidUpdate(prevProps)
{
if (prevProps.timer.tick !== this.props.timer.tick)
{
console.log('TIMER UPDATED: ' + this.props.timer.tick);
}
}
render() { return null; }
}
Timer = reactTimer(2525)(Timer)
ReactDOM.render(<Timer timerTick={1000}/>, document.getElementById('root'));
The above code snippet causes this HOC timer to update its tick value twice per delay (of 1000ms)