Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: do something while all components are mounted

As in title: how can I do something while all components are mounted in React? I'd like to run script which needs all my components to be mounted.

like image 563
Karol Selak Avatar asked Sep 21 '26 09:09

Karol Selak


1 Answers

React knows to mount first all child components before calling componentDidMount on the parent component.

So, you can use componentDidMount callback method in your main component.

As soon as the render method has been executed, the componentDidMount function is called. The DOM can be accessed in this method, enabling to define DOM manipulations or data fetching operations.

like image 164
Mihai Alexandru-Ionut Avatar answered Sep 24 '26 02:09

Mihai Alexandru-Ionut