Current component has state.breaker
value of false. When the scroll event is captured it looks at the state
and if its false
it does some stuff.
I would like to have some kind of static delay before the action will recur and that's why inside goTo
function the state.breaker
is set to true
and will block the the further logic of current method for next 2s
until setTimeout
will return back to false
.
But at the current moment the following error occurs Uncaught TypeError: this.setState is not a function when setState
is called inside setTimeout
.
class Slide extends Component {
constructor(props) {
super(props)
this.state = {
breaker: false
}
this.scrollRedirect = this.scrollRedirect.bind(this);
}
componentDidMount() {
this.refs.holder.addEventListener('mousewheel', this.scrollRedirect);
}
scrollRedirect(e) {
const path = this.props.location.pathname,
goTo = (route) => {
this.setState({breaker: true});
hashHistory.push(route);
setTimeout(function () {
this.setState({breaker: false});
}, 2000)
};
if (!this.state.breaker) {
... code that executes goTo on condition
}
}
... render code
}