Note that screenLayout is called as a function, not a component#1503
Open
Noitidart wants to merge 1 commit into
Open
Note that screenLayout is called as a function, not a component#1503Noitidart wants to merge 1 commit into
Noitidart wants to merge 1 commit into
Conversation
✅ Deploy Preview for react-navigation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
screenLayoutdocumentation describes it as "a function that returns a React element," and all examples return JSX immediately. This is correct but implicit — a developer who needs to call a hook insidescreenLayout(e.g., to read theme context, access app state, etc.) discovers only at runtime that React throws:The root cause is that React Navigation invokes
screenLayoutvia a plain function call (useDescriptors.tsx:267-275), not via JSX. Hooks called inside have no React fiber to register against. The misleading "conditionally" wording in React's error sent me searching for a conditional that didn't exist.Solution
Add a warning block (with workaround) after the existing
screenLayoutexamples in bothnavigator.mdandgroup.mdfor v7 and v8. The workaround is to wrap hook logic in a real component and return it as JSX — then React mounts it properly and hooks work.Why
I hit this myself and lost real time to it. The current examples all return JSX immediately (which sidesteps the issue), so there's no way to anticipate it from reading the docs. The error message points at conditional hook calls, but the actual problem is the function-invocation pattern — which the docs don't currently surface.
Scope
Same note added to all 4 files where the screenLayout section appears:
versioned_docs/version-7.x/navigator.mdversioned_docs/version-7.x/group.mdversioned_docs/version-8.x/navigator.mdversioned_docs/version-8.x/group.mdMarked as a
:::warningrather than:::notefor visual prominence — this is a real footgun, not a footnote. Existing:::warningblocks in these files (e.g., theRoutersection about experimental APIs) use the same styling.Verified
markdownlint-cli2andprettierboth pass on the changed files.