Last active
February 21, 2016 04:29
-
-
Save codemilli/d2a5548cb3b98f5ae2a7 to your computer and use it in GitHub Desktop.
component 들을 redux 와 연결하는 app container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
import * as ActionCreators from '../actions'; | |
import Add from '../components/add'; | |
import Todos from '../components/todos'; | |
import Header from '../components/header'; | |
/** | |
* Define React Presentational Component App | |
*/ | |
const App = (props) => { | |
const {toggleTodo, createTodo, setVisible, visible, todos} = props; | |
return ( | |
<div> | |
<Header setVisible={setVisible} visible={visible} /> | |
<Add onSubmit={createTodo} /> | |
<Todos todos={todos} onToggle={toggleTodo} /> | |
</div> | |
); | |
}; | |
const getVisibleTodos = (todos, visible) => { | |
switch(visible) { | |
case 'SHOW_COMPLETED': | |
return todos.filter(t => t.completed); | |
case 'SHOW_UNCOMPLETED': | |
return todos.filter(t => !t.completed); | |
case 'SHOW_ALL': | |
default: | |
return todos; | |
} | |
}; | |
const mapStateToProps = (state) => { | |
return { | |
todos: getVisibleTodos(state.todos, state.visible), | |
visible: state.visible | |
}; | |
}; | |
const mapDispatchToProps = (dispatch) => { | |
return bindActionCreators(ActionCreators, dispatch); | |
}; | |
export default connect( | |
mapStateToProps, | |
mapDispatchToProps | |
)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment