mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Add links to event pooling docs
This commit is contained in:
@@ -182,6 +182,8 @@ class Alphabet extends React.Component {
|
||||
|
||||
If you have an event handler such as `onClick` or `onScroll` and want to prevent the callback from being fired too quickly, you can wrap the handler with a utility such as [`_.debounce`](https://lodash.com/docs#debounce) or [`_.throttle`](https://lodash.com/docs#throttle). For a given `delay`, say `100ms`, debouncing calls the handler after activity stops for that amount of time; throttling prevents the handler from being called more than once per `delay`. See a visualization [here](http://demo.nimius.net/debounce_throttle/).
|
||||
|
||||
Note: Call `event.persist()` when accessing events asynchronously to prevent the synthetic event from being recycled by [event pooling](/docs/events.html#event-pooling). See the debounce [example](#debounce) below.
|
||||
|
||||
#### Throttle
|
||||
|
||||
```jsx
|
||||
@@ -205,7 +207,7 @@ import debounce from 'lodash.debounce'
|
||||
|
||||
class Searchbox extends React.Component {
|
||||
handleChange = event => {
|
||||
event.persist()
|
||||
event.persist() // https://reactjs.org/docs/events.html#event-pooling
|
||||
this._handleChangeDebounced(event.target.value)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user