Created
June 8, 2016 16:05
-
-
Save callmephilip/9eb8da23c8771093faac02a7b00967e2 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 { TextInput } from 'react-native'; | |
import React, { Component } from 'react'; | |
import styles from './styles'; | |
import { connect } from 'react-redux'; | |
import { addTask } from '../TodoList/actions'; | |
class AddTodoItem extends Component { | |
render() { | |
return ( | |
<TextInput | |
ref={ input => { this._textBox = input; } } | |
autoCorrect={false} | |
placeholder={ 'What needs to be done?' } | |
style={ styles.textBox } | |
onChangeText={(text) => this.setState({ text })} | |
onSubmitEditing={this.saveTodoItem.bind(this)} | |
/> | |
); | |
} | |
saveTodoItem () { | |
this.props.addTask(this.state.text); | |
this._textBox.clear(); | |
} | |
} | |
function mapDispatchToProps(dispatch) { | |
return { | |
dispatch, | |
addTask (text) { | |
dispatch(addTask(text)); | |
} | |
}; | |
} | |
export default connect(() => ({}), mapDispatchToProps)(AddTodoItem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment