How to fix error 'FB' is not defined no-undef on create-react-app project?

后端 未结 5 932
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 02:51

I made the project using this link as my starting file.

https://github.com/facebookincubator/create-react-app

But after i tried to make Facebook login button

相关标签:
5条回答
  • 2020-12-30 03:13

    Based on what @dan-abramov stated in a comment to another answer:

    Don't use FB, use window.FB

    This way, you define explicitely where the variable FB needs to come from.

    0 讨论(0)
  • 2020-12-30 03:14

    If you use Create React App, you need to explicitly grab global variables from window.
    For example:

    // It's a global so need to read it from window
    const FB = window.FB;
    

    However, if the library is available as an npm package, you can use imports:

    // It's an npm package so you can import it
    import $ from 'jquery';
    

    I hope this helps!

    0 讨论(0)
  • 2020-12-30 03:14

    Put this in your .eslintrc file, so you only have to define it once and not in every single file:

    "globals": {
        "FB": true
    }
    
    0 讨论(0)
  • 2020-12-30 03:20

    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*/

    For more information, check out the "Rule Details" section on the official ESLint docs: http://eslint.org/docs/rules/no-undef

    0 讨论(0)
  • 2020-12-30 03:20

    I can fix this by use this.FB instead just FB

    0 讨论(0)
提交回复
热议问题