Var*_*kul 14 facebook reactjs eslint create-react-app
我使用此链接作为我的起始文件制作了项目.
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'));
}
Run Code Online (Sandbox Code Playgroud)
所以我在刷新浏览器时遇到了这个错误.
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)
Run Code Online (Sandbox Code Playgroud)
所以我猜因为ESLint导致了这个错误.我该如何解决这个问题或者为这个FB变量做例外?
谢谢!
Dan*_*mov 12
如果您使用Create React App,则需要显式地从中获取全局变量window.
例如:
// It's a global so need to read it from window
const FB = window.FB;
Run Code Online (Sandbox Code Playgroud)
但是,如果库可用作npm包,则可以使用导入:
// It's an npm package so you can import it
import $ from 'jquery';
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助!
| 归档时间: |
|
| 查看次数: |
7860 次 |
| 最近记录: |