-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add ability to debounce window resize updates #4
base: master
Are you sure you want to change the base?
Conversation
This allows a user to pass a debounceMs when calling useWindowSize in order to debounce the window resize events
please don't include formatting changes with your PR |
you're still changing the formatting with indentation |
@jamiebuilds I'm working on it :) It certainly wasn't my intention to change your formatting. the first commit was through code sandbox and it applied prettier automatically |
any objection to adding a prettier config to maintain your formatting? I'm happy to get one set up in another PR |
Sure, could you submit a PR to https://github.com/rehooks/template |
What about receiving the debounce function as an argument?
|
That could be pretty cool to allow a user to pass a function to apply to the event handler before updating state, then they could pick throttle, debounce, filter, etc, etc. However, I'm not sure lodash/debounce works like that. I think debounce takes a fn as the first arg, delay as second. We could specify that they give us a function that will take our fn as an arg? Kind of wonky though. import { debounce as _debounce, throttle as _throttle } from 'lodash/fp';
let debounce = delay => fn => _debounce(fn, delay)
let throttle = delay => fn => _throttle(fn, delay)
function App() {
let windowWidth = useWindowWidth();
let debouncedWindowWidth = useWindowWidth(debounce(500))
let throttledWindowWidth = useWindowWidth(throttle(500))
return [
<pre>Debounced: {JSON.stringify(debouncedWindowWidth)}</pre>,
<pre>Throttled: {JSON.stringify(throttledWindowWidth)}</pre>,
<pre>Firehose: {JSON.stringify(windowWidth)}</pre>,
]
} 🤷♂️ Is there a better way? |
@camflan the |
@camflan @jamesb3ll If you pass a function argument to I mean I guess you could only use the first function ever passed, but that might violate some users' assumption that they can pass a function with a different delay to change throttle/debounce rate. |
@camflan to elaborate on what @jamesb3ll said, AFAIK |
This allows a user to pass a debounceMs when calling useWindowSize in order to debounce the window resize events