I
I
IIITRIX2019-05-25 21:42:18
React
IIITRIX, 2019-05-25 21:42:18

How to change parent element class when hovering over child?

constructor(){
    super();
    this.state = {
        isHovered: false
    };
    this.handleHover = this.handleHover.bind(this);
}
handleHover(){
    this.setState(prevState => ({
        isHovered: !prevState.isHovered
    }));
}
render(){
    const btnClass = this.state.isHovered ? "pulse" : "";
    return (
      <div className="РОДИТЕЛЬ"></div>
      <div className={btnClass} onMouseEnter={this.handleHover} onMouseLeave={this.handleHover}></div>
    )
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-25
@IIITRIX

lifting state up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question