reactjs - 类型 'typeof class' 不可分配给类型 'ComponentType<any>'

标签 reactjs typescript react-native

我正在尝试使用 typescript 使用 React Native 导航,我得到了一个 Type 'typeof LoginScreen' is not assignable to type 'ComponentType<any>'尝试连接我的屏幕时出错。

class App extends React.Component {
  render() {
    return (
      <NavigationContainer>
        <Stack.Navigator initialRouteName="Login">
          <Stack.Screen name="Login" component={LoginScreen} />
        </Stack.Navigator>
      </NavigationContainer>
    );
  }
}

class LoginScreen extends React.Component {
  render() {
    const {navigate} = this.props.navigation;
  }
}

这在 component={LoginScreen} 处失败。 我知道这是因为我的 React 组件“HomeScreen”不需要任何 Prop ,但是处理这个问题的安全方法是什么,因为我看到了许多不同的解决方案。

最佳答案

我找到了问题的答案。您可以使用 https://reactnavigation.org/docs/1.x/navigation-prop/其中有关于如何处理这个确切案例的文档。希望这对某些人有所帮助。

关于reactjs - 类型 'typeof class' 不可分配给类型 'ComponentType<any>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61646322/

相关文章:

ios - 在 React Native 中隐藏/显示基于服务/动态地来自 json 的标签 <Text>

javascript - 通过具有未定义字段的数组进行映射

javascript - React Router 路径错误匹配

node.js - Docker 容器正在运行,但其进程已完成

node.js - 在 Observable 中返回自己的静态值

reactjs - 无法在 React Native 应用程序中使用 React.memo

javascript - 需要 Babel "^7.0.0-0",但在react-xml-parser包上加载了 "6.26.3"- 已经尝试了所有当前的解决方案

node.js - 将音频 Blob 数据从 React 前端发送到 Express 后端

angular - 使用 ES 模块导入 object-set-all-values-to 时出错

react-native - 如何在 React Native 中混合两种类型的导航