Skip to content

Instantly share code, notes, and snippets.

@cmilfont
Last active December 21, 2016 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmilfont/637c194ab58e9bb37c991c3b16179c0a to your computer and use it in GitHub Desktop.
Save cmilfont/637c194ab58e9bb37c991c3b16179c0a to your computer and use it in GitHub Desktop.
Real World - incomplete, but an idea
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);
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