Created
May 22, 2017 13:27
-
-
Save Louiefigz/6220dc5257e63cc8658bd9bcb429275b 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'; | |
class BandInput extends Component{ | |
constructor(){ | |
super(); | |
this.state={ | |
text: "" | |
} | |
} | |
handleOnChange(e){ | |
e.preventDefault(); | |
this.setState({ | |
text: e.target.value | |
}) | |
} | |
// Below we are going to be using the dispatch function from createStore.js in order | |
// to change our state. We are sending in the tyoe and then the band data as an object. | |
handleOnSubmit(e){ | |
e.preventDefault(); | |
this.props.store.dispatch({ | |
type: 'ADD_BAND', | |
band: { | |
text: this.state.text, | |
}, | |
}); | |
this.setState({ | |
text: '' | |
}); | |
} | |
render(){ | |
return( | |
<div> | |
<form onSubmit={(event) => this.handleOnSubmit(event)}> | |
<input type="text" onChange={(event) => this.handleOnChange(event)} /> | |
<input type="submit" /> | |
</form> | |
</div> | |
) | |
} | |
} | |
export default BandInput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment