![](/img/trans.png)
[英]React/Redux: separating presentational and container components dilemma.
[英]React with redux and component vs. container dilemma
我想將代碼組織成components
和containers
文件夾結構。 我將Redux與動作和reducer一起使用。
您認為StartButton
是組件還是容器? 它不會連接到redux存儲,但是它具有自己的狀態和一些決策邏輯,因此它可能並不愚蠢...
我知道我的問題與觀點有關,但也許有人可以向我提供一些見解以及什么是最佳實踐。
這是我的StartButton組件:
import React, { Component } from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import './style.css';
class StartButton extends Component {
constructor() {
super();
this.state = {
startWasClicked: false,
};
}
handleStartButton = () => {
this.setState({ startWasClicked: true });
};
beerListingView() {
if (this.state.startWasClicked) {
return <div>YES! It was clicked!</div>;
}
// Else return just single <div />
return <div />;
}
render() {
return (
<div>
<div className="StartButton-container">
<RaisedButton
label="Start Here"
className="StartButton-main"
onClick={this.handleStartButton}
/>
</div>
{this.beerListingView()}
</div>
);
}
}
export default StartButton;
在我的應用程序中, containers
是指連接到Redux存儲的react組件。
所有其他components
。 例如,它們大多數都使用React狀態來切換UI內容。 很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.