google is not defined in react app using create-react-app

前端 未结 4 1657
攒了一身酷
攒了一身酷 2020-12-08 14:51

I create a react app using the cli called create-react-app. Look like Facebook did lots of things underneath, such as webpack etc. However, I guess it may also has some limi

4条回答
  •  -上瘾入骨i
    2020-12-08 14:54

    I have a better solution then @Dan's you can do it like this

    window.google = window.google ? window.google : {}
    

    OR

    const google = window.google = window.google ? window.google : {}
    

    If google is available then no problem if not then empty will be assigned till your scripts are loaded.

提交回复
热议问题