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

Use useSyncExternalStore for useWindowDimensions hook instead of useState #49481

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lewiscasewell
Copy link

@lewiscasewell lewiscasewell commented Feb 17, 2025

Summary:

  • Uses React 18’s recommended way to subscribe to external stores (useSyncExternalStore). So it is centralised vs creating separate state instances for each hook call.
  • Optimised for concurrent rendering.
  • Uses startTransition(), making updates low priority, so UI stays responsive. Which works well when the window is resized rapidly - e.g. in web

Changelog:

[GENERAL] [CHANGED] - Use useSyncExternalStore for useWindowDimensions hook instead of useState

Test Plan:

interface is identical to before so

const window = useWindowDimensions();

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Feb 17, 2025
@lewiscasewell lewiscasewell changed the title Use useSyncExternalStore for useWindowDimensions hook instead of useState Use useSyncExternalStore for useWindowDimensions hook instead of useState Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants