デバウンス関数は、JSX でインラインで渡すか、次のようにクラス メソッドとして直接設定できます。
search: _.debounce(function(e) {
console.log('Debounced Event:', e);
}, 1000)
フィドル: https://jsfiddle.net/woodenconsulting/69z2wepo/36453/
es2015+ を使用している場合は、デバウンス メソッドを直接、constructor
または のようなライフサイクル メソッドで定義できますcomponentWillMount
。
例:
class DebounceSamples extends React.Component {
constructor(props) {
super(props);
// Method defined in constructor, alternatively could be in another lifecycle method
// like componentWillMount
this.search = _.debounce(e => {
console.log('Debounced Event:', e);
}, 1000);
}
// Define the method directly in your class
search = _.debounce((e) => {
console.log('Debounced Event:', e);
}, 1000)
}