diff --git a/versioned_docs/version-7.x/group.md b/versioned_docs/version-7.x/group.md index 1ff642c138..8772cb4834 100644 --- a/versioned_docs/version-7.x/group.md +++ b/versioned_docs/version-7.x/group.md @@ -287,6 +287,26 @@ const MyStack = createNativeStackNavigator({ +:::warning + +The function passed to `screenLayout` is invoked as a regular function, not rendered as a React component. This means you **cannot call React Hooks directly inside it** — doing so will fail at runtime with errors such as _"Should have a queue. You are likely calling Hooks conditionally, which is not allowed."_ + +If you need to use Hooks, wrap your logic in a separate component and return it as JSX: + +```jsx +function MyScreenLayout(props) { + const value = useMyHook(); // ✅ Hook runs inside a real component + + return {props.children}; +} + +const Stack = createNativeStackNavigator({ + screenLayout: (props) => , +}); +``` + +::: + ### Navigation key Optional key for a group of screens. If the key changes, all existing screens in this group will be removed (if used in a stack navigator) or reset (if used in a tab or drawer navigator): diff --git a/versioned_docs/version-7.x/navigator.md b/versioned_docs/version-7.x/navigator.md index aa39797a55..795c58f5ef 100644 --- a/versioned_docs/version-7.x/navigator.md +++ b/versioned_docs/version-7.x/navigator.md @@ -310,6 +310,26 @@ function MyStack() { +:::warning + +The function passed to `screenLayout` is invoked as a regular function, not rendered as a React component. This means you **cannot call React Hooks directly inside it** — doing so will fail at runtime with errors such as _"Should have a queue. You are likely calling Hooks conditionally, which is not allowed."_ + +If you need to use Hooks, wrap your logic in a separate component and return it as JSX: + +```jsx +function MyScreenLayout(props) { + const value = useMyHook(); // ✅ Hook runs inside a real component + + return {props.children}; +} + +const Stack = createNativeStackNavigator({ + screenLayout: (props) => , +}); +``` + +::: + ### Router :::warning diff --git a/versioned_docs/version-8.x/group.md b/versioned_docs/version-8.x/group.md index 17793f8a58..118332e8ba 100644 --- a/versioned_docs/version-8.x/group.md +++ b/versioned_docs/version-8.x/group.md @@ -287,6 +287,26 @@ const MyStack = createNativeStackNavigator({ +:::warning + +The function passed to `screenLayout` is invoked as a regular function, not rendered as a React component. This means you **cannot call React Hooks directly inside it** — doing so will fail at runtime with errors such as _"Should have a queue. You are likely calling Hooks conditionally, which is not allowed."_ + +If you need to use Hooks, wrap your logic in a separate component and return it as JSX: + +```jsx +function MyScreenLayout(props) { + const value = useMyHook(); // ✅ Hook runs inside a real component + + return {props.children}; +} + +const Stack = createNativeStackNavigator({ + screenLayout: (props) => , +}); +``` + +::: + ### Navigation key Optional key for a group of screens. If the key changes, all existing screens in this group will be removed (if used in a stack navigator) or reset (if used in a tab or drawer navigator): diff --git a/versioned_docs/version-8.x/navigator.md b/versioned_docs/version-8.x/navigator.md index 4ba7a5f3f6..289a8f9053 100644 --- a/versioned_docs/version-8.x/navigator.md +++ b/versioned_docs/version-8.x/navigator.md @@ -270,6 +270,26 @@ function MyStack() { +:::warning + +The function passed to `screenLayout` is invoked as a regular function, not rendered as a React component. This means you **cannot call React Hooks directly inside it** — doing so will fail at runtime with errors such as _"Should have a queue. You are likely calling Hooks conditionally, which is not allowed."_ + +If you need to use Hooks, wrap your logic in a separate component and return it as JSX: + +```jsx +function MyScreenLayout(props) { + const value = useMyHook(); // ✅ Hook runs inside a real component + + return {props.children}; +} + +const Stack = createNativeStackNavigator({ + screenLayout: (props) => , +}); +``` + +::: + ### Router Routers can be customized with the `router` prop on navigator to override how navigation actions are handled.