【问题标题】:Invariant Violation : Usage Issue for npm Library不变违规:npm 库的使用问题
【发布时间】:2016-12-19 08:42:11
【问题描述】:

我正在尝试使用在 npm site 中找到的 react-google-login,但我遇到了一些问题。错误是

bundle.js:3104 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method ofLogin.

bundle.js:3104 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method ofLogin

这可能是因为使用问题。我也可能没有正确导入。非常感谢任何帮助。

var React = require('react')
var GoogleLogin = require('react-google-login')
var Login = React.createClass({
    responseGoogle(e){
        console.log("response",e)
    },
    render:function(){
        return <div>
          <GoogleLogin
            clientId="xxxxxxxxxxx-yyyyyyyyyy.apps.googleusercontent.com"
            buttonText="Login"
            callback={this.responseGoogle} />
        </div>
    },
});
module.exports = Login;

~

这很可能是调用了不需要的函数或类。我一直在使用require,但我不熟悉导入。任何有关在未来找出正确语法的正确方法的建议或注释也非常感谢。

【问题讨论】:

    标签: javascript node.js reactjs import babeljs


    【解决方案1】:

    你试过了吗:

    var GoogleLogin = require('react-google-login').default
    

    【讨论】:

      【解决方案2】:

      你需要添加一行来导出你的组件。

      export default Login;
      

      【讨论】:

      • 抱歉,这不起作用。如果我使用导入可能会起作用吗?
      • 它肯定会与 import 一起使用,它应该与 this 一起使用.. 检查此链接一次 toddmotto.com/react-create-class-versus-component
      • 非常感谢您的链接!
      猜你喜欢
      • 2015-09-28
      • 2015-07-18
      • 2016-02-19
      • 1970-01-01
      • 2016-01-30
      • 2020-05-06
      • 2022-10-18
      • 2020-03-20
      • 2020-10-02
      相关资源
      最近更新 更多