-
Notifications
You must be signed in to change notification settings - Fork 370
chore(resizeObserver): refactored use of useRequestAnimationFrame #8324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { canUseDOM } from './util'; | |
* private observer: any = () => {}; | ||
* | ||
* public componentDidMount() { | ||
* this.observer = getResizeObserver(this.containerRef.current, this.handleResize); | ||
* this.observer = getResizeObserver(this.containerRef.current, this.handleResize, true); | ||
* } | ||
* | ||
* public componentWillUnmount() { | ||
|
@@ -37,7 +37,7 @@ import { canUseDOM } from './util'; | |
* private observer: any = () => {}; | ||
* | ||
* public componentDidMount() { | ||
* this.observer = getResizeObserver(this.inputRef.current, this.handleResize); | ||
* this.observer = getResizeObserver(this.inputRef.current, this.handleResize, true); | ||
* } | ||
* | ||
* public componentWillUnmount() { | ||
|
@@ -59,18 +59,18 @@ import { canUseDOM } from './util'; | |
* Example 3 - With debounced method passed in: | ||
* | ||
* public componentDidMount() { | ||
* this.observer = getResizeObserver(this.inputRef.current, debounce(this.handleResize, 250), false); | ||
* this.observer = getResizeObserver(this.inputRef.current, debounce(this.handleResize, 250)); | ||
* } | ||
* | ||
* @param {Element} containerRefElement The container reference to observe | ||
* @param {Function} handleResize The function to call for resize events | ||
* @param {boolean} useRequestAnimationFrame Whether to pass the handleResize function as a callback to requestAnimationFrame. Pass in false when the function passed in is debounced. Defaults to true. | ||
* @param {boolean} useRequestAnimationFrame Whether to pass the handleResize function as a callback to requestAnimationFrame. Pass in true when the function passed in is not debounced. | ||
* @return {Function} The function used to unobserve resize events | ||
*/ | ||
export const getResizeObserver = ( | ||
containerRefElement: Element, | ||
handleResize: () => void, | ||
useRequestAnimationFrame: boolean = true | ||
useRequestAnimationFrame?: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IS it worth adding some comment here about when to set this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's blocked out in the files tab, but I did previously add this description for the parameter:
That said I just pushed another commit to update the description since it was slightly inaccurate after this update. |
||
) => { | ||
let unobserve: any; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
useRequestAnimationFrame
is opt-in, thinking we should leave this off the examples. Don't feel strongly about it, but we don't need it for most cases.