My script for react-google-maps don't loads

元气小坏坏 提交于 2019-12-24 10:36:08

问题


i want to render the component Searchbox, i copied it exactly in my app, but i get an error:

error  Line 44:  'google' is not defined  no-undef   Line 79:  'google' is not defined  no-undef 

i already loaded my

<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_KEY_IS_HERE"></script>

into the head of my index.html but it showes me the error anyway. Could it be, that index.html can't load my script ?

i created my app with create-react-app


回答1:


It is probably your linter complaining about an undefined variable. Because 'google' is defined in a script that loads externally with <script> tag, your linter doesn't know about it. Try adding an exception for the variable. In eslint you would add this line at the top of the file where you access the variable: /*global google*/ But since you have the async attribute in your <script> tag, your script may still run before the maps API is executed. One solution would be to remove the async and defer attributes. But if you really want the maps API to load asynchronously, then you could try an additional library, like react-async-script-loader. Here's a discussion about a similar problem.



来源:https://stackoverflow.com/questions/46540253/my-script-for-react-google-maps-dont-loads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!