Alex
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
7 additions and
8 deletions
-
content/docs/faq-functions.md
|
@ -185,7 +185,7 @@ If you have an event handler such as `onClick` or `onScroll` and want to prevent |
|
|
#### Throttle |
|
|
#### Throttle |
|
|
|
|
|
|
|
|
```jsx |
|
|
```jsx |
|
|
import { throttle } from 'lodash' |
|
|
import throttle from 'lodash.throttle' |
|
|
|
|
|
|
|
|
class LoadMoreButton extends React.Component { |
|
|
class LoadMoreButton extends React.Component { |
|
|
handleClick = throttle(() => { |
|
|
handleClick = throttle(() => { |
|
@ -201,18 +201,17 @@ class LoadMoreButton extends React.Component { |
|
|
#### Debounce |
|
|
#### Debounce |
|
|
|
|
|
|
|
|
```jsx |
|
|
```jsx |
|
|
import { debounce } from 'lodash' |
|
|
import debounce from 'lodash.debounce' |
|
|
|
|
|
|
|
|
class Searchbox extends React.Component { |
|
|
class Searchbox extends React.Component { |
|
|
handleChange = event => { |
|
|
handleChange = event => { |
|
|
event.persist() |
|
|
event.persist() |
|
|
this._handleChangeDebounced(event) |
|
|
this._handleChangeDebounced(event.target.value) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
_handleChangeDebounced = debounce(event => { |
|
|
_handleChangeDebounced = debounce(value => { |
|
|
this.props.onChange(event.target.value) |
|
|
this.props.onChange(value) |
|
|
}, 250) |
|
|
}, 250) |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
return ( |
|
|
return ( |
|
|