如何在react-navigation v5中使用withNavigation?

lea*_*r62 5 react-native react-navigation-v5

withNavigation我有一个嵌套组件,我想在react-navigation v5中的嵌套组件中使用。

Ehs*_*har 8

为什么你不创建自己的withNavigation

import React from 'react';
import { useNavigation } from '@react-navigation/native'; // not sure package name

export const withNavigation = (Component: any) => {
  return (props: any) => {
    const navigation = useNavigation();

    return <Component navigation={navigation} {...props} />;
  };
};
Run Code Online (Sandbox Code Playgroud)