Skip to content
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

Closed
yairopro opened this issue Jan 31, 2022 · 5 comments
Closed

useWindowDimensions() isn't debounced #33005

yairopro opened this issue Jan 31, 2022 · 5 comments
Labels
API: Dimensions Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@yairopro
Copy link

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 each change 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

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 31, 2022
@yairopro
Copy link
Author

yairopro commented Aug 3, 2022

🤖💀

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 4, 2022
@kennethstarkrl
Copy link

kennethstarkrl commented Mar 24, 2024

+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 Dimensions.get('window').width to work around the issue but can no longer adjust some components based off the window size without a full reload. Even with using it at lower level components causes problems. I haven't found a good solution for dynamic window adjustments.

@react-native-bot
Copy link
Collaborator

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.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 20, 2024
@react-native-bot
Copy link
Collaborator

This issue was closed because it has been stalled for 7 days with no activity.

@react-native-bot react-native-bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Dimensions Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants