Last active
December 11, 2016 19:53
-
-
Save Donmclean/13d055a78d481bd513173838ea2eed6d to your computer and use it in GitHub Desktop.
React Snippets
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, PropTypes } from 'react'; | |
import _ from 'lodash'; | |
class SomeComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.fetchAjaxFromDebouncedInput = _.debounce(this.fetchAjaxFromDebouncedInput, 3000); | |
} | |
fetchAjaxFromDebouncedInput(event) { | |
//handle ajax from debounced event here... | |
} | |
handleKeyStrokes(event) { | |
//http://stackoverflow.com/questions/23123138/perform-debounce-in-react-js | |
event.persist(); //<--- This is key | |
this.fetchAjaxFromDebouncedInput(event); | |
} | |
render() { | |
return ( | |
<div className="example-input"> | |
<input onChange={this.handleKeyStrokes.bind(this)} placeholder="Enter text" type="text"/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment