我是React的新手。我不是在this code理解部分:react.js的道具如何声明
var HelloMessage = React.createClass({
render: function() {
return <h2>{this.props.message}</h2>;
}
});
var TextBox = React.createClass({
getInitialState: function() {
return { isEditing: false }
},
update: function() {
// Where is props.update defined? //
this.props.update(this.refs.messageTextBox.value);
this.setState(
{
isEditing: false
});
},
edit: function() {
this.setState({ isEditing: true});
},
在代码中,我找不到props
声明update
。但仔细查看代码,我们应该看到“更新”作为TextBox组件的属性。
我没有在任何渲染方法中看到this.props.update
的明确声明。
如何/在哪里定义了props.update
?
属性及其组件的值(作为JSX)是组件的键和值(作为React元素) – sudhnk
谢谢我能够找出属性的起源与您的回应 – CodeZilla
嗨!我编辑了你的文章,使其更具可读性,所以你可以得到你需要的帮助。我在你的例子中添加了一些代码。你应该总是包含你的代码的[minimal working example](https://stackoverflow.com/help/mcve)以及你所看到的任何错误。我知道你想知道更多关于React的内部工作原理,但是如果你没有发布像我之前提到的那些引用,那么你不太可能得到帮助。祝你好运! –