J
J
Juniorrrrr2020-04-22 16:05:19
JavaScript
Juniorrrrr, 2020-04-22 16:05:19

How can React listen for a field change on the global window object?

Tell me, there is a third-party script from Yandex that embeds the Ya.
In my custom component, I need to listen for a change in the window.Ya.adfoxCode field and, in the case when it appears, do something.

I use useEffect, but if you specify window.Ya as a dependency, then the effect does not work.

How can this problem be better solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-22
@hzzzzl

hmmm, probably not, because window is outside the react application,
but if it is known that window.Ya.adfoxCode appears, then it can check
if ('Ya' in window) {....} through setInterval
and then remove the interval as soon as possible straightaway

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question