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(props); this.state = { activeMediaIndex: 0 }; } componentDidMount() { setInterval(this.changeActiveMedia.bind(this), 5000); } changeActiveMedia() { const mediaListLength = this.props.mediaList.length; let nextMediaIndex = this.state.activeMediaIndex + 1; if(nextMediaIndex >= mediaListLength) { nextMediaIndex = 0; } this