Skip to content Skip to sidebar Skip to footer

Unmounting A Component With A Setinterval In React

I'm trying to unmount a component with a setInterval. This is based on the answer here: Component: class ImageSlider extends React.Component { constructor(props) { super(pro

Solution 1:

setInterval returns an in interval Id that you can use in clearInterval.

More info on setInterval

Something like this should work:

this.myInterval = setInterval(this.changeActiveMedia.bind(this), 5000)

then in componentWillUnmount:

clearInterval(this.myInterval);

Post a Comment for "Unmounting A Component With A Setinterval In React"