[英]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.