Created
May 25, 2017 15:13
-
-
Save Louiefigz/366078b923bfabb49c10922f9394b7df to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component } from "react"; | |
import { connect } from 'react-redux'; | |
//Add the Code below to add the action addTask. | |
import { addTask } from '../actions/TaskAction'; | |
class UserInput extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
task: '' | |
}; | |
} | |
handleChange(event) { | |
this.setState({ | |
task: event.target.value | |
}); | |
} | |
handleOnSubmit(event) { | |
event.preventDefault(); | |
//Using the action addTask below in order to package the data for the reducer. | |
this.props.dispatch(addTask(this.state.task)) | |
} | |
render() { | |
return( | |
<form onSubmit={(event) => this.handleOnSubmit(event)}> | |
<p> | |
<input | |
type="text" | |
onChange={(event) => this.handleChange(event)} | |
placeholder="enter name"/> | |
</p> | |
<input type="submit" /> | |
</form> | |
) | |
} | |
} | |
export default connect(undefined)(UserInput) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment