Skip to content

Instantly share code, notes, and snippets.

@callmephilip
Created June 8, 2016 16:05
Show Gist options
  • Save callmephilip/9eb8da23c8771093faac02a7b00967e2 to your computer and use it in GitHub Desktop.
Save callmephilip/9eb8da23c8771093faac02a7b00967e2 to your computer and use it in GitHub Desktop.
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