react-timer-hoc icon indicating copy to clipboard operation
react-timer-hoc copied to clipboard

Use of setDelay causing multiple timer updates

Open ShaneCallanan opened this issue 7 years ago • 0 comments

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)

ShaneCallanan avatar Dec 11 '18 14:12 ShaneCallanan