Skip to content

fix(reference): declare subscribe before passing it to the hook (issue #7707) #7711

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

Merged

Conversation

hugmouse
Copy link
Contributor

@hugmouse hugmouse commented Apr 2, 2025

Fixes the typo in the docs, related issue: #7707

Context from the issue

The following code will throw Uncaught TypeError: subscribe is not a function.

function ChatIndicator({ userId }) {
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
// ✅ Same function as long as userId doesn't change
const subscribe = useCallback(() => {
// ...
}, [userId]);
// ...
}

Documentation page: https://react.dev/reference/react/useSyncExternalStore#my-subscribe-function-gets-called-after-every-re-render

Fix

Just declaring subscribe before passing it to the hook.

Screenshot

In case you don't want to check out the auto-generated preview :)

Screenshot of a section "My subscribe function gets called after every re-render" and related documentation of it

Copy link

vercel bot commented Apr 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-dev ✅ Ready (Inspect) Visit Preview Apr 2, 2025 9:03am

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants