Last active
August 3, 2016 05:23
-
-
Save jfeldstein/c071dc8021988578800a10eb40a8577c to your computer and use it in GitHub Desktop.
Notes on React:
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
class TodoApp extends Component { | |
mapStateToProps: (state) => ({ | |
// Take a selection of the state, applying business logic to prepare it for consumption by a presentational component which is unaware of any business rules. | |
items: state.items.filter(i => i.visible) | |
}) | |
mapDispatchToProps: (dispatch) => ({ | |
// Callbacks which interact with the rest of the app | |
onClick: (id) => dispatch({type: "TOGGLE_TODO", id}), | |
}) | |
render: () => { | |
return ( | |
// TodoList is the presenter. We pass it all the prepared props. | |
<TodoList {...this.props} /> | |
) | |
} | |
} |
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
const TodoList = ({items, onClick}) => | |
// Doesn't know anything about what onClick does, or why it is getting the items it's given. Just shows them. | |
<ul> | |
{items.map(todo => <TodoItem key={todo.id} onClick={() => onClick(todo.id)} {...todo} /> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment