0

I know how it can be done with onClick, for adding a new css class for example:

wheelFade = (event) => {
   event.target.classList.add('newClass');
}

render(){
    return(
       <img onClick={this.wheelFade} className="wheel1" src="wheel.png" alt=""/>
    )
   }

But if I want to add a class to the img tag using a setTimtOut for example how can I access the img tag without having the event.target that I do get on click?

Thanks in advance

1 Answer 1

1

References would work.

constructor(props) {
  ...
  this.image = null;
}

render() {
  return (
    <img ref={image => this.image = image} />
  )
}

Once rendered, you can access the element by using this.image

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.