-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
useWindowDimensions() isn't debounced #33005
Comments
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
🤖💀 |
+1 this behavior will kill performance just for simple window resizing. If you're using this in a higher level page component it causes a re-rendering nightmare even with React.memo because the props do change. Especially if you're using a flatlist because vertical scrolling causes a height adjustment and re-renders all the components in the flatlist. Went with |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Description
I think
useWindowDimensions()
hook should be debounced (and maybe make the debouncing time configurable) since it triggers a render of the components calling it at eachchange
event. On desktop (web or native) it's common for a user to resize its app/browser window. So the event is going to be fired at each small resize, causing the components to render multiple times at once.Version
master
Output of
npx react-native info
No need.
Steps to reproduce
Call
useWindowDimensions()
and resize the window.Snack, code example, screenshot, or link to a repository
In this sandbox, when you resize the width of the preview, it fires the log
render
multiple times.https://codesandbox.io/s/late-violet-je3hz?file=/src/App.js
The text was updated successfully, but these errors were encountered: