ReactJS Webpack错误类型.toUpperCase不是函数

时间:2015-09-02 15:37:18

标签: javascript reactjs webpack

所以我使用webpack将我的react组件捆绑到myApp.js中。我在我的webpack.config.js文件中创建了一个名为MyApp的全局公开变量,该文件包含我的所有反应组件 - 如下所示:

entry: {
// create myApp.js, expose MyApp global object  
// index.js lists all my react components to include in myApp.js
        'myApp.js': 'expose?MyApp!../ReactComponents/index.js'
    },

现在在javascript中,当我使用以下语法来渲染我的react组件时,我得到错误类型.toUpperCase不是函数:

// MyApp.Employees - MyApp is the global object 
// and Employees is my react component within MyApp global object

    window.onload = function () {
// type is object and not null
// so it is found
alert(MyApp.Employees); 

// react will not render it though
// using this syntax
        React.render(React.createElement(MyApp.Employees, null), document.getElementById('react'));
    }

我一直收到错误类型.toUpperCase不是函数。

对呈现MyApp.Employees做出反应的语法是什么?

或者可能导致此错误的原因是什么?

感谢任何建议!

2 个答案:

答案 0 :(得分:0)

似乎您已经拥有由React创建的Employees组件,并且您尝试在该组件上使用createElement

尝试

var Employees = MyApp.Employees;
React.render(<Employees />, document.getElementById('react'));

答案 1 :(得分:0)

尝试使用

String.prototype.toLocaleUpperCase.call('your string'); 

String.prototype.toUpperCase.call('your string'); 
相关问题