如何修复在create-react-app项目上未定义错误'FB'的no-undef? [英] How to fix error 'FB' is not defined no-undef on create-react-app project?
问题描述
我使用此链接作为我的起始文件来创建项目。
I made the project using this link as my starting file.
https://github.com/facebookincubator/create-react-app
但是在我尝试设置Facebook登录按钮后
But after i tried to make Facebook login button with follow by their official docs with this.
componentDidMount(){
console.log('login mount');
window.fbAsyncInit = function() {
FB.init({
appId : '320866754951228',
xfbml : true,
version : 'v2.6'
});
FB.getLoginStatus(function(response) {
//this.statusChangeCallback(response);
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
所以刷新浏览器时出现此错误。
So i got this errors when the browser was refreshed.
Failed to compile.
Error in ./src/components/user_profile/LoginForm.js
/Sites/full_stack_production/xxxxx
70:13 error 'FB' is not defined no-undef
76:13 error 'FB' is not defined no-undef
✖ 2 problems (2 errors, 0 warnings)
所以我想是因为ESLint导致了此错误。
如何解决此问题或对该 FB
变量进行例外处理?
So i guess because ESLint that cause this errors.
How can i fix this or make the exception for this FB
variable?
谢谢!
推荐答案
ESLint不知道变量 FB
是全局变量。您可以通过在文件顶部添加以下内容来声明引用为全局变量:
ESLint doesn't know that the variable FB
is a global. You can declare a variable you referenced as a global by adding the following to the top of your file:
/ * global FB * /
有关更多信息,请查看官方ESLint文档上的规则详细信息部分: http://eslint.org/docs/rules/no-undef
For more information, check out the "Rule Details" section on the official ESLint docs: http://eslint.org/docs/rules/no-undef
这篇关于如何修复在create-react-app项目上未定义错误'FB'的no-undef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!