【发布时间】:2017-03-20 20:58:37
【问题描述】:
我使用这个链接作为我的起始文件制作了这个项目。
https://github.com/facebookincubator/create-react-app
但在我尝试制作 Facebook 登录按钮后,他们的官方文档会关注这个。
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'));
}
所以刷新浏览器时出现此错误。
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 变量设置例外?
谢谢!
【问题讨论】:
-
由于 FB 是全局的,而 create-react-app 是模块,您可能需要对此进行填充。即使出现错误,应用程序也能正常工作吗? stackoverflow.com/questions/5331165/…
标签: facebook reactjs eslint create-react-app