@@ -4,30 +4,28 @@ import {
4
4
NavigationContainer ,
5
5
NavigationContext ,
6
6
} from '@react-navigation/native' ;
7
- import { createStackNavigator } from '@react-navigation/stack' ;
7
+ import { createNativeStackNavigator } from '@react-navigation/native- stack' ;
8
8
9
9
function HomeScreen ( ) {
10
10
return < SomeComponent /> ;
11
11
}
12
12
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
+ ) ;
29
26
}
30
27
28
+
31
29
function ProfileScreen ( { navigation } ) {
32
30
return (
33
31
< View style = { { flex : 1 , alignItems : 'center' , justifyContent : 'center' } } >
@@ -36,7 +34,7 @@ function ProfileScreen({ navigation }) {
36
34
) ;
37
35
}
38
36
39
- const Stack = createStackNavigator ( ) ;
37
+ const Stack = createNativeStackNavigator ( ) ;
40
38
41
39
function App ( ) {
42
40
return (
0 commit comments