1.Presentational and Container Components
Presentational Components | Container Components | |
---|---|---|
Purpose | How things look (markup, styles) | How things work (data fetching, state updates) |
Aware of Redux | No | Yes |
To read data | Read data from props | Subscribe to Redux state |
To change data | Invoke callbacks from props | Dispatch Redux actions |
Are written | By hand | Usually generated by React Redux |
2.components/home-view
& containers/HomeView
2.1 home-view components
2.2 HomeView container
import {
Header,
Main,
} from '../components/home-view';
import Actions from '../actions';
class HomeView extends Component {
render() {
return (
<View>
<Header {...this.props}/>
<Main {...this.props} isVisible={this.state.isVisible}/>
</View>
);
}
}
function mapStateToProps(state) {
return {
todos: state.todos
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(Actions, dispatch)
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(HomeView);