useIsInitialScreen
A hook that checks whether the current screen is the first screen in the navigation stack. Internally, it uses useNavigationState
to check if the current stack's index
is 0. Use this when you want to conditionally display a back button or show specific guidance messages only on the initial screen.
Signature
typescript
function useIsInitialScreen(): boolean;
Return Value
- boolean
Returns
true
if the current screen is the first screen in the navigation stack, otherwise returnsfalse
.
Examples
Display a Welcome Message Only on the Initial Screen
An example that shows a welcome message only when entering the first screen.
tsx
import { useIsInitialScreen } from '@granite-js/react-native';
import { Text, View } from 'react-native';
function MyScreen() {
const isInitialScreen = useIsInitialScreen();
return (
<View>
{isInitialScreen && <Text>Welcome! This is the initial screen.</Text>}
<Text>Screen content</Text>
</View>
);
}