K
K
Kerhin2019-06-24 19:05:37
JavaScript
Kerhin, 2019-06-24 19:05:37

How to add a class to an element and then remove it from the DOM tree without a click in React?

There is a problem with the implementation of the function. We need to add a class
to an existing element ( ) ( say with the name .addClass ) 3 seconds after the page loads, and then completely remove this element from the DOM tree, after 5 seconds, let's say. But to make it all happen without a click. I understand that for this you need to use the onLoad event, conditions, setTimeout timer-scheduler, but unfortunately I have not come up with anything good yet. <div className="block"></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-24
@Kerhin

Let there be two boolean properties in the state - one is responsible for rendering the element, the other for adding a class. In componentDidMount you set timeouts for changing these properties. Everything.
UPD. https://jsfiddle.net/4yq5du0r/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question