React window.Calendly undefined

228 views Asked by At
  useEffect(() => {
    // I've initiated Calendly in this effect
  }, [])

  console.log(window.Calendly)

I got undefined when I print window.Calendly, but when I print just window, I got an object contains Calendly.

1

There are 1 answers

2
Nicholas Tower On BEST ANSWER

Effects run after rendering. So you're logging first, and then setting up window.Calendly later.

When you switch to logging window, you're now logging an object. The developer tools do not evaluate what's in that object until you click to inspect it. So by the time you click, window.Calendly exists, but it didn't exist when the log statement ran.