0

A client wants to add their own event listeners to an app I've created. They will wait for the DOM content to load, then apply click handlers to certain elements in my app (to which I've added unique IDs).

However, it seems like React doesn't emit a window.onload or equivalent when all content is loaded, because currently my client is having to manually set a timeout in order to successfully apply the click handlers.

Here's what they've implemented:

<script>
    $(document).ready(function() {
        setTimeout(function(){
            $("#1button").click(function() {           
              location.href = $(this).attr("href");
            });
            $("#2button").click(function() {
              location.href = $(this).attr("href");
            });
        }, 1000); 
    });

</script>

AFAIK the jquery ready function is equivalent to document.addEventListener('DOMContentLoaded', ...) although I haven't yet asked them if they've tried this pure JS version.

At any rate, it seems like React isn't ready when the document is ready. Does React send out some other kind of even when it's finished loading? One that my client can listen for to then apply their click handlers.

crevulus
  • 1,658
  • 12
  • 42

0 Answers0