Skip to content

Instantly share code, notes, and snippets.

@jfeldstein
Last active August 3, 2016 05:23
Show Gist options
  • Save jfeldstein/c071dc8021988578800a10eb40a8577c to your computer and use it in GitHub Desktop.
Save jfeldstein/c071dc8021988578800a10eb40a8577c to your computer and use it in GitHub Desktop.
Notes on React:
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} />
)
}
}
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