diff --git a/sidebars.js b/sidebars.js deleted file mode 100755 index 2c1f4c9e5de..00000000000 --- a/sidebars.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - docs: { } -}; diff --git a/static/examples/7.x/go-back.js b/static/examples/7.x/go-back.js index e2417a2cf9d..ed6b1dbbc07 100755 --- a/static/examples/7.x/go-back.js +++ b/static/examples/7.x/go-back.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/multiple-navigate.js b/static/examples/7.x/multiple-navigate.js index 8e4ecc94b25..ddb83a07768 100755 --- a/static/examples/7.x/multiple-navigate.js +++ b/static/examples/7.x/multiple-navigate.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/multiple-push.js b/static/examples/7.x/multiple-push.js index 32c8f1126a9..21f2213a1b1 100755 --- a/static/examples/7.x/multiple-push.js +++ b/static/examples/7.x/multiple-push.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/new-screen.js b/static/examples/7.x/new-screen.js index 7d7e4991edb..21c7b472f92 100755 --- a/static/examples/7.x/new-screen.js +++ b/static/examples/7.x/new-screen.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen diff --git a/static/examples/7.x/params-nested-navigators.js b/static/examples/7.x/params-nested-navigators.js index dbb8959679b..d2a20a7cad8 100755 --- a/static/examples/7.x/params-nested-navigators.js +++ b/static/examples/7.x/params-nested-navigators.js @@ -1,10 +1,12 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createDrawerNavigator } from '@react-navigation/drawer'; -function SettingsScreen({ route, navigation }) { +function SettingsScreen({ route }) { + const navigation = useNavigation(); + const { user } = route.params; return ( @@ -18,7 +20,9 @@ function SettingsScreen({ route, navigation }) { ); } -function ProfileScreen({ navigation }) { +function ProfileScreen() { + const navigation = useNavigation(); + return ( Profile Screen @@ -26,7 +30,9 @@ function ProfileScreen({ navigation }) { ); } -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen diff --git a/static/examples/7.x/passing-params-back.js b/static/examples/7.x/passing-params-back.js index 5a2a6051c5d..3c392ef963e 100755 --- a/static/examples/7.x/passing-params-back.js +++ b/static/examples/7.x/passing-params-back.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Text, TextInput, View, Button } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation, route }) { +function HomeScreen({ route }) { + const navigation = useNavigation(); + React.useEffect(() => { if (route.params?.post) { // Post updated, do something with `route.params.post` @@ -22,7 +24,8 @@ function HomeScreen({ navigation, route }) { ); } -function CreatePostScreen({ navigation, route }) { +function CreatePostScreen({ route }) { + const navigation = useNavigation(); const [postText, setPostText] = React.useState(''); return ( diff --git a/static/examples/7.x/passing-params.js b/static/examples/7.x/passing-params.js index 5a43e8c6d51..78a3586dd0e 100755 --- a/static/examples/7.x/passing-params.js +++ b/static/examples/7.x/passing-params.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Text, View, Button } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -21,7 +23,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ route, navigation }) { +function DetailsScreen({ route }) { + const navigation = useNavigation(); + /* 2. Get the param */ const { itemId } = route.params; const { otherParam } = route.params; diff --git a/static/examples/7.x/pop-to-top.js b/static/examples/7.x/pop-to-top.js index 83dd5f08a7c..4d108ad612e 100755 --- a/static/examples/7.x/pop-to-top.js +++ b/static/examples/7.x/pop-to-top.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/versioned_docs/version-7.x/bottom-tab-navigator.md b/versioned_docs/version-7.x/bottom-tab-navigator.md index 35ac873c811..1582b919c58 100755 --- a/versioned_docs/version-7.x/bottom-tab-navigator.md +++ b/versioned_docs/version-7.x/bottom-tab-navigator.md @@ -53,7 +53,7 @@ The `Tab.Navigator` component accepts following props: #### `id` -Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-prop.md#getparent) to refer to this navigator in a child navigator. +Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-object.md#getparent) to refer to this navigator in a child navigator. #### `initialRouteName` @@ -442,7 +442,7 @@ React.useEffect(() => { ### Helpers -The tab navigator adds the following methods to the navigation prop: +The tab navigator adds the following methods to the navigation object: #### `jumpTo` diff --git a/versioned_docs/version-7.x/connecting-navigation-prop.md b/versioned_docs/version-7.x/connecting-navigation-prop.md deleted file mode 100755 index 628cedd792e..00000000000 --- a/versioned_docs/version-7.x/connecting-navigation-prop.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -id: connecting-navigation-prop -title: Access the navigation prop from any component -sidebar_label: Access the navigation prop from any component ---- - -[`useNavigation`](use-navigation.md) is a hook which gives access to the `navigation` object. It's useful when you cannot pass the `navigation` prop into the component directly, or don't want to pass it in case of a deeply nested child. - -An ordinary component that is not a screen component will not receive the navigation prop automatically. For example in this `GoToButton` component: - -```js -import * as React from 'react'; -import { Button } from 'react-native'; - -function GoToButton({ navigation, screenName }) { - return ( -