-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d3592d
commit 99b9f60
Showing
2 changed files
with
45 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
|
||
class PostMessageForm extends React.Component { | ||
constructor( props, context ) { | ||
super( props, context ); | ||
|
||
this.handleSubmit = this.handleSubmit.bind( this ); | ||
} | ||
handleSubmit( event ) { | ||
event.preventDefault(); | ||
this.props.appendChatMessage( this.nameInput.value, this.messageInput.value ); | ||
this.nameInput.value = ''; | ||
this.messageInput.value = ''; | ||
} | ||
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit.bind(this)}> | ||
This comment has been minimized.
Sorry, something went wrong. |
||
<input type="text" | ||
ref={name => this.nameInput = name} | ||
placeholder="Name" /> | ||
<input type="text" | ||
ref={message => this.messageInput = message} | ||
placeholder="Message" /> | ||
<input type="submit" value="Send" /> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
export default PostMessageForm; |
Line 17 is redundant:
.bind( this )
is not required, as context binding is performed in the constructor (Line 7).Generally, it is better not to do any context binding in the render method for performance reasons, as a new handler is created on each render.