Skip to content

Instantly share code, notes, and snippets.

@kanerogers
Last active May 30, 2016 10:15
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 kanerogers/2d20d96932226c5b8c5173b8f928cdf9 to your computer and use it in GitHub Desktop.
Save kanerogers/2d20d96932226c5b8c5173b8f928cdf9 to your computer and use it in GitHub Desktop.
import React from 'react';
import TouchableOpacity from 'react-native';
import { connect } from 'react-redux';
export const mapStateToProps = (state) => {
todos: state.todos,
};
export const mapDispatchToProps = (dispatch) => {
toggleTodo: (id) => dispatch({type: 'TOGGLE_TODO', id }),
};
const Todo = ({ todo, onPress }) => (
<TouchableOpacity onPress={onPress}>
<Text>{todo.text}</Text>
</TouchableOpacity>
);
export const TodosComponent = ({ todos, toggleTodo }) => (
todos.map(t => <Todo todo={t} onPress={toggleTodo(t.id)} />)
);
const Todos = connect(mapStateToProps, mapDispatchToProps)(TodosComponent);
export default Todos;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment