Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when ReactJS has finished page manipulation?

Tags:

reactjs

Our clients add our JS tag to the head of their page. Our tag needs to know when reactJS has finished before it modifies the page.

I have tried using jQuery's $(document).ready() but this fires before reactJS has finished. I can use $(window).load() but if there are a lot of images on the page, this would be too slow.

What are the options to bind to the completion of React.renderComponent?

like image 792
Graeme MacFarlane Avatar asked Dec 25 '22 05:12

Graeme MacFarlane


1 Answers

Set off the execution of your code via the optional callback that you can pass to React.renderComponent. This callback won't execute until React.renderComponent has finished. If you don't have access to the code that is executing React.renderComponent (which I've just realized is almost definitely the case) then there is no definitive/reliable way to listen for the execution of a function unless of course that function exposes some sort of event that you can listen for, or even guarantees that "x" will be the case once it has finished. Sadly for your case, this doesn't appear to be an option with React.renderComponent.. Let me know if you have any further question.

like image 178
pooley1994 Avatar answered Dec 28 '22 15:12

pooley1994