Home > Software engineering >  Error in React app: window.functionFromThirdParty is not a function
Error in React app: window.functionFromThirdParty is not a function

Time:01-26

From a third party I have to add a function to the window object:

In my React child component I added it like:

useEffect(() => {
   window.functionFromThirdParty();
  }, [id]);

But then I get this error:

Uncaught TypeError: window.functionFromThirdParty is not a function

How to fix this issue?

CodePudding user response:

Make sure that the function is actually being added to the window object by the third party code. You can check this by running console.log(window) in the browser's developer console and seeing if the function is listed.

CodePudding user response:

It is either related to third party conflict, or you did not import that function properly, could you try to give us more info and specifically where you imported it into window object.

  • Related