Last active
December 21, 2016 11:52
-
-
Save cmilfont/637c194ab58e9bb37c991c3b16179c0a to your computer and use it in GitHub Desktop.
Real World - incomplete, but an idea
This file contains 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, { PropTypes } from 'react'; | |
import { connect } from 'react-redux'; | |
import FormContainer from './form.jsx'; | |
import List from './List.jsx'; | |
/* Export function to unit tests */ | |
export const TodoList = (todos, create) => ( | |
<div> | |
<FormContainer submit={create} /> | |
<List todos={todos} /> | |
</div> | |
); | |
TodoList.propTypes = { | |
create: PropTypes.func.isRequired, | |
todos: PropTypes.arrayOf(PropTypes.shape({ | |
text: PropTypes.string, | |
})) | |
}; | |
const mapStateToProps = ({ todos } => ({ todos })); | |
const mapDispatchToProps = dispatch => ({ | |
create: (payload) => dispatch({ | |
type: 'TODO_CREATE', | |
payload, | |
}), | |
}); | |
// export a connected container | |
export default connect(mapStateToProps, mapDispatchToProps)(TodoList); |
This file contains 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, { PropTypes } from 'react'; | |
export const List = (todos) => { | |
const list = todos.map(({text}) => (<div className="todo">{text}</div>)); | |
return ( | |
<div className="TodoList"> | |
{list} | |
</div> | |
); | |
} | |
List.PropTypes = {}; | |
export default List; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment