Skip to content

Commit 0022825

Browse files
myyellowshoeflarnie
authored andcommitted
Small update keybinding docs. (facebookarchive#1023)
* Bind handleKeyCommand in the constructor. It's bad practice to bind functions in render. Updated it to handle binding in the constructor. so it is only bound once. * Update Advanced-Topics-Key-Bindings.md
1 parent d6cad2e commit 0022825

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

docs/Advanced-Topics-Key-Bindings.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ In our editor component, we can then make use of the command via the
6969
```js
7070
import {Editor} from 'draft-js';
7171
class MyEditor extends React.Component {
72-
// ...
7372

73+
constructor(props) {
74+
super(props);
75+
this.handleKeyCommand = this.handleKeyCommand.bind(this);
76+
}
77+
// ...
78+
7479
handleKeyCommand(command: string): DraftHandleValue {
7580
if (command === 'myeditor-save') {
7681
// Perform a request to save your contents, set
@@ -84,7 +89,7 @@ class MyEditor extends React.Component {
8489
return (
8590
<Editor
8691
editorState={this.state.editorState}
87-
handleKeyCommand={this.handleKeyCommand.bind(this)}
92+
handleKeyCommand={this.handleKeyCommand}
8893
keyBindingFn={myKeyBindingFn}
8994
...
9095
/>

0 commit comments

Comments
 (0)