[英]React.js Cannot read property '__reactAutoBindMap' of null
我知道這已經被問過了,但是建議的解決方案對我沒有幫助,因此,這是我的代碼,由於某種原因它失敗了。
app.js:
(function(React, _) {
var App = require('./components/App.react');
_.mixin(_.string.exports());
var render = function() {
React.render(
React.createElement(App),
document.getElementById('reactContent')
);
};
render();
}(React, _));
然后,App.react.js:
var React = require('react');
var Test = React.createClass({
render: function() {
return <div>Hello world</div>
}
})
module.exports = Test;
現在,我的控制台說:
Warning: This JSX uses a plain function. Only React components are valid in React's JSX transform.
app.js:20281 Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory
app.js:6475 Uncaught TypeError: Cannot read property '__reactAutoBindMap' of null
感覺像最簡單的事情...我將包含package.json,以防萬一。
{
"name": "app",
"version": "0.0.1",
"devDependencies": {
"gulp": "3.8.10",
"gulp-run": "1.6.5",
"gulp-less": "2.0.1",
"gulp-concat": "2.4.3",
"gulp-uglify": "1.0.2",
"gulp-minify-css": "0.3.11",
"gulp-jshint": "1.9.0",
"browser-sync": "1.8.2",
"browserify": "3.44.2",
"vinyl-source-stream": "1.0.0",
"vinyl-buffer": "1.0.0",
"reactify": "latest",
"underscore": "^1.7.0",
"del": "1.1.1",
"envify": "~3.0.0"
},
"paths": {
"less": "assets/less/*.less",
"js": "./app/**/*.js",
"jsx": "./app/**/*.jsx",
"app": "./app/app.js",
"html": "*.html"
},
"dest": {
"style": "style.css",
"app": "app.js",
"dist": "dist"
},
"dependencies": {
"react": "latest",
"underscore": "^1.7.0",
"flux": "^2.0.0"
}
}
從.json文件中可以看到,這里還有更多內容,我只是重新構建了代碼,以制作一個非常簡單的案例並找出問題所在。
有任何想法嗎?
我認為您需要React.createFactory(require('./components/App.react'))
如下所述: https : React.createFactory(require('./components/App.react'))
或使用ES6類: https ://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html
編輯:我找到了原始的博客文章: https : //facebook.github.io/react/blog/2014/10/14/introducing-react-elements.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.