Skip to content

Commit b2f6c66

Browse files
docs: use native-stack in navigation-context
1 parent 8d6789f commit b2f6c66

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

static/examples/6.x/navigation-context.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@ import {
44
NavigationContainer,
55
NavigationContext,
66
} from '@react-navigation/native';
7-
import { createStackNavigator } from '@react-navigation/stack';
7+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
88

99
function HomeScreen() {
1010
return <SomeComponent />;
1111
}
1212

13-
class SomeComponent extends React.Component {
14-
static contextType = NavigationContext;
15-
16-
render() {
17-
// We can access navigation object via context
18-
const navigation = this.context;
19-
return (
20-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
21-
<Text>Some component inside HomeScreen</Text>
22-
<Button
23-
onPress={() => navigation.navigate('Profile')}
24-
title="Go to Profile"
25-
/>
26-
</View>
27-
);
28-
}
13+
function SomeComponent() {
14+
// We can access navigation object via context
15+
const navigation = React.useContext(NavigationContext);
16+
17+
return (
18+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
19+
<Text>Some component inside HomeScreen</Text>
20+
<Button
21+
onPress={() => navigation.navigate('Profile')}
22+
title="Go to Profile"
23+
/>
24+
</View>
25+
);
2926
}
3027

28+
3129
function ProfileScreen({ navigation }) {
3230
return (
3331
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
@@ -36,7 +34,7 @@ function ProfileScreen({ navigation }) {
3634
);
3735
}
3836

39-
const Stack = createStackNavigator();
37+
const Stack = createNativeStackNavigator();
4038

4139
function App() {
4240
return (

versioned_docs/version-6.x/navigation-context.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ Example:
1515
```js
1616
import { NavigationContext } from '@react-navigation/native';
1717

18-
class SomeComponent extends React.Component {
19-
static contextType = NavigationContext;
20-
21-
render() {
22-
// We can access navigation object via context
23-
const navigation = this.context;
24-
}
18+
function SomeComponent() {
19+
// We can access navigation object via context
20+
const navigation = React.useContext(NavigationContext);
2521
}
2622
```

0 commit comments

Comments
 (0)