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

useSubscription: fix rules of React violations #11863

Merged
merged 14 commits into from
Jul 3, 2024
Prev Previous commit
Next Next commit
clarify comment
phryneas committed Jul 3, 2024
commit 654d94964cbdae1a758dbeaf7607c21100af8117
4 changes: 3 additions & 1 deletion src/react/hooks/useSubscription.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,9 @@ import { useSyncExternalStore } from "./useSyncExternalStore.js";
* @remarks
* #### Consider using `onData` instead of `useEffect`
*
* If you want to react to incoming data, please use the `onData` option instead of `useEffect`. State updates you make inside a `useEffect` hook might cause additional rerenders, and `useEffect` is mostly meant for side effects of rendering, not as an event handler.
* If you want to react to incoming data, please use the `onData` option instead of `useEffect`.
* State updates you make inside a `useEffect` hook might cause additional rerenders, and `useEffect` is mostly meant for side effects of rendering, not as an event handler.
* State updates made in an event handler like `onData` might - depending on the React version - be batched and cause only a single rerender.
*
* Consider the following component:
*