Skip to content

Commit 2aab945

Browse files
committed
Note that screenLayout is called as a function, not a component
1 parent 001e32c commit 2aab945

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

versioned_docs/version-7.x/group.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ const MyStack = createNativeStackNavigator({
287287
</TabItem>
288288
</ConfigTabs>
289289

290+
:::warning
291+
292+
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."_
293+
294+
If you need to use Hooks, wrap your logic in a separate component and return it as JSX:
295+
296+
```jsx
297+
function MyScreenLayout(props) {
298+
const value = useMyHook(); // ✅ Hook runs inside a real component
299+
300+
return <ErrorBoundary>{props.children}</ErrorBoundary>;
301+
}
302+
303+
const Stack = createNativeStackNavigator({
304+
screenLayout: (props) => <MyScreenLayout {...props} />,
305+
});
306+
```
307+
308+
:::
309+
290310
### Navigation key
291311

292312
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):

versioned_docs/version-7.x/navigator.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,26 @@ function MyStack() {
310310
</TabItem>
311311
</ConfigTabs>
312312

313+
:::warning
314+
315+
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."_
316+
317+
If you need to use Hooks, wrap your logic in a separate component and return it as JSX:
318+
319+
```jsx
320+
function MyScreenLayout(props) {
321+
const value = useMyHook(); // ✅ Hook runs inside a real component
322+
323+
return <ErrorBoundary>{props.children}</ErrorBoundary>;
324+
}
325+
326+
const Stack = createNativeStackNavigator({
327+
screenLayout: (props) => <MyScreenLayout {...props} />,
328+
});
329+
```
330+
331+
:::
332+
313333
### Router
314334

315335
:::warning

versioned_docs/version-8.x/group.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ const MyStack = createNativeStackNavigator({
287287
</TabItem>
288288
</ConfigTabs>
289289

290+
:::warning
291+
292+
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."_
293+
294+
If you need to use Hooks, wrap your logic in a separate component and return it as JSX:
295+
296+
```jsx
297+
function MyScreenLayout(props) {
298+
const value = useMyHook(); // ✅ Hook runs inside a real component
299+
300+
return <ErrorBoundary>{props.children}</ErrorBoundary>;
301+
}
302+
303+
const Stack = createNativeStackNavigator({
304+
screenLayout: (props) => <MyScreenLayout {...props} />,
305+
});
306+
```
307+
308+
:::
309+
290310
### Navigation key
291311

292312
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):

versioned_docs/version-8.x/navigator.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,26 @@ function MyStack() {
270270
</TabItem>
271271
</ConfigTabs>
272272

273+
:::warning
274+
275+
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."_
276+
277+
If you need to use Hooks, wrap your logic in a separate component and return it as JSX:
278+
279+
```jsx
280+
function MyScreenLayout(props) {
281+
const value = useMyHook(); // ✅ Hook runs inside a real component
282+
283+
return <ErrorBoundary>{props.children}</ErrorBoundary>;
284+
}
285+
286+
const Stack = createNativeStackNavigator({
287+
screenLayout: (props) => <MyScreenLayout {...props} />,
288+
});
289+
```
290+
291+
:::
292+
273293
### Router
274294

275295
Routers can be customized with the `router` prop on navigator to override how navigation actions are handled.

0 commit comments

Comments
 (0)