react-navigation/Insights
React Navigation Insights
Key learnings and patterns for React Navigation
insightsreact-navigationnavigationmobile
React Navigation Insights
Key Learnings
Setup Patterns
-
Native Stack Recommended
react-navigation/native-stackprovides better performance than the JS-based stack. -
Safe Area Context Wrap navigator with
SafeAreaProviderto handle device notches. -
Types for Params Define TypeScript interfaces for screen params to ensure type safety.
Navigation Types
| Type | Use Case | Performance | |------|----------|-------------| | Native Stack | Stack navigation | Best on native | | Bottom Tabs | Tab-based apps | Good, native bottom tabs | | Drawer | Side menu | Good, native drawer |
Linking Deep Links
const linking = {
prefixes: ['myapp://', 'https://myapp.com'],
config: {
screens: {
Chat: 'chat/:threadId',
},
},
};
Auth Flow Pattern
<Stack.Navigator>
{!isAuthenticated ? (
<>
<Stack.Screen name="Login" />
<Stack.Screen name="Register" />
</>
) : (
<>
<Stack.Screen name="Home" />
<Stack.Screen name="Chat" />
</>
)}
</Stack.Navigator>
Gotchas
headerShown: falseon nested screens won't hide parent header- Use
navigation.goBack()instead ofnavigation.navigate()for back - Screen options can be overridden at the component level with
useLayoutEffect