[英]How to transfer props in react v0.13?
I'm trying to learn react for my first javascript project and as a start creating a very simple code that adds two numbers entered in a text box. 我正在尝试学习我的第一个javascript项目的反应,并作为一个开始创建一个非常简单的代码,添加在文本框中输入的两个数字。 The result is re-rendered as a number is typed.
在键入数字时重新呈现结果。 This worked for me on react v0.11.
这对我起作用反应v0.11。
var App = React.createClass({
mixins: [React.addons.LinkedStateMixin],
getInitialState: function() {
return {
payment: 0,
payment2: 0
};
},
render: function() {
var total = parseInt(this.state.payment, 10) +
parseInt(this.state.payment2, 10);
return (
<div>
<Payment {...this.props} valueLink={this.linkState('payment')}/><span>+</span>
<Payment {...this.props} valueLink={this.linkState('payment2')}/><span>=</span>
{ total }
</div>
);
}
});
var Payment = React.createClass({
render: function() {
return this.transferPropsTo(
<input type="text" />
);
}
});
React.render(
<App />,
document.getElementById('app')
);
However, it seems like the transferPropsTo() function was removed in v0.13. 但是,似乎在v0.13中删除了transferPropsTo()函数。 How do I do the equivalent in the latest version.
我如何在最新版本中执行等效操作。
You can pass {...this.props}
in the input tag: 您可以在输入标记中传递
{...this.props}
:
var Payment = React.createClass({
render: function() {
return (
<input type="text" {...this.props} />
);
}
});
This uses the JSX spread attributes feature. 这使用JSX 传播属性功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.