![](/img/trans.png)
[英]React.js: shouldComponentUpdate in array of stateless child Components
[英]Implementing a stateless child component in React.js
我正在尝试实现一个无状态的React组件,该组件将在页脚中显示方向(作为文本),我称之为Direction
组件。 该组件旨在包含在其他父组件中,它们代表不同的页面,这些页面在必要的方向上传递,作为由Direction
组件呈现的道具。
// direction.js
'use strict';
var React = require('react');
var Direction = React.createClass({
propTypes: {
directionText: React.PropTypes.string.isRequired
},
render: function() {
return (
<div className="direction">
<p className="direction-text">
{this.props.directionText}
</p>
</div>
);
}
});
module.exports = Direction;
// controller.js
var DirectionController = {
// not sure how to configure it
};
我不确定如何配置controller
。
我什至需要controller
,因为此组件将仅呈现文本并且不处理用户交互性?
这个组件应该像我想的那么简单吗?
我是React的新手。
您仅在需要时将Direction组件包含在渲染中,并在属性directionText中传递要显示的内容
render: function() {
<div className="whatever-class">
<Direction directionText="Some text to show" />
<Direction directionText="Some some more more text text" />
</div>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.