Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesseanwright/0f0a2784c7df348e0ca3dec8998a83f0 to your computer and use it in GitHub Desktop.
Save jamesseanwright/0f0a2784c7df348e0ca3dec8998a83f0 to your computer and use it in GitHub Desktop.
React State with Backing Instance Example
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