Created
December 20, 2018 18:29
-
-
Save jamesseanwright/0f0a2784c7df348e0ca3dec8998a83f0 to your computer and use it in GitHub Desktop.
React State with Backing Instance Example
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
class MessageForm extends React.Component<Props, State> { | |
constructor(props: Props) { | |
super(props); | |
this.state = { | |
message: '', | |
}; | |
} | |
render() { | |
const { submitMessage } = this.props; | |
return ( | |
<form onSubmit={e => { | |
e.preventDefault(); | |
submitMessage(this.state.message); | |
}}> | |
<input | |
type="text" | |
onChange={e => this.setState({ | |
message: e.currentTarget.value, | |
})} | |
/> | |
<input | |
type="submit" | |
value="Add" | |
/> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment