Answer the question
In order to leave comments, you need to log in
How to delay onMouseEnter in React?
People, in general, there is such a state of affairs:
toggleHover() {
this.setState({ hover: !this.state.hover });
}
onMouseEnter={this::this.toggleHover} onMouseLeave={this::this.toggleHover}>
Answer the question
In order to leave comments, you need to log in
I only recommend making this function via debounce (or equivalents):
constructor(props) {
super(props);
const finalMouseDelay = props.mouseDelay || 300;
this.handleMouseLeave = this.handleMouseLeave.bind(this);
this.handleMouseEnter = this.handleMouseEnter.bind(this);
this.toggleHover = _.debounce(this.toggleHover.bind(this), finalMouseDelay);
this.state = { hover: false };
}
handleMouseLeave() {
this.toggleHover(false);
}
handleMouseEnter() {
this.toggleHover(true);
}
toggleHover(to) {
this.setState({ hover: to });
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question