NavigationContext
NavigationContext
提供 navigation
对象(与 navigation 属性相同的对象)。事实上,useNavigation 使用此上下文来获取 navigation
属性。
¥NavigationContext
provides the navigation
object (same object as the navigation prop). In fact, useNavigation uses this context to get the navigation
prop.
大多数时候,你不会直接使用 NavigationContext
,因为提供的 useNavigation
涵盖了大多数用例。但如果你有其他想法,NavigationContext
可供你使用。
¥Most of the time, you won't use NavigationContext
directly, as the provided useNavigation
covers most use cases. But just in case you have something else in mind, NavigationContext
is available for you to use.
示例:
¥Example:
- Static
- Dynamic
import { NavigationContext } from '@react-navigation/native';
function SomeComponent() {
// We can access navigation object via context
const navigation = React.useContext(NavigationContext);
import { NavigationContext } from '@react-navigation/native';
function SomeComponent() {
// We can access navigation object via context
const navigation = React.useContext(NavigationContext);