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

[react] Use useSyncExternalStore for external subscriptions #311

Open
prichodko opened this issue Sep 26, 2022 · 0 comments
Open

[react] Use useSyncExternalStore for external subscriptions #311

prichodko opened this issue Sep 26, 2022 · 0 comments
Assignees
Labels
architecture Internal changes concerning how the application works. status-react

Comments

@prichodko
Copy link
Collaborator

prichodko commented Sep 26, 2022

Since React 18, there is a more correct way to subscribe to external stores using the React's built-in useSyncExternalStore hook.

From the React docs:

useSyncExternalStore is a hook recommended for reading and subscribing from external data sources in a way that’s compatible with concurrent rendering features like selective hydration and time slicing.

To support apps using React below version 18, there is a package called use-sync-external-store/shim. This shim will prefer useSyncExternalStore when available, and fallback to a user-space implementation when it’s not.

@prichodko prichodko added the architecture Internal changes concerning how the application works. label Sep 26, 2022
@prichodko prichodko self-assigned this Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Internal changes concerning how the application works. status-react
Projects
None yet
Development

No branches or pull requests

1 participant