Last active
May 30, 2016 10:15
-
-
Save kanerogers/2d20d96932226c5b8c5173b8f928cdf9 to your computer and use it in GitHub Desktop.
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 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