我正在阅读“ React Native for iOS Development”这本书,以学习没有任何react.js经验的React Native开发。一些代码使我困惑了一段时间,其中一个在注释之后:
var App = React.createClass({
render: function() {
// why there is this line and what does 'this' in the line stand for?
var txt = this.props.txt
return (
<div>
<h1>{myProp}</h1>
</div>
);
},
});
React.render(
<App myProp='Hi from prop' />, document.getElementById('container'));
这是整个js文件,将从html文件引用该文件,该文件中有一个具有id =“ container”属性的div标签。而已。任何帮助将不胜感激。
似乎此代码中有错误,该行应为
var myProp = this.props.myProp
this
在这种情况下,它是对将要渲染的React组件的引用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句