我试图将一个数字传递给 React 组件,但它被解析为字符串 ( jsfiddle )。我如何让 React 明白我传递的是一个数字?我应该将字符串转换为组件中的数字吗?
var Rectangle = React.createClass({
render: function() {
return <div>
<div>{this.props.intValue + 10}</div>
<div>{this.props.stringValue + 10}</div>
</div>;
}
});
React.render(<Rectangle intValue="10" stringValue="Hello" />
, document.getElementById('container'));
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
最佳答案
似乎在整数的情况下(实际上对于字符串也是如此)我应该通过 {}
传递数字像这样:
React.render(<Rectangle intValue={10} stringValue={"Hello"} />, document.getElementById('container'));
关于javascript - 将数字传递给组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29474673/