D.T Fadel
D.T Fadel

Reputation: 103

React window.Calendly undefined

  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.

Upvotes: 1

Views: 271

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 85062

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.

Upvotes: 2

Related Questions