![](/img/trans.png)
[英]Argument of type 'typeof LogoAvatar' is not assignable to parameter of type 'ComponentType<LogoProps & Partial<WithTheme>
[英]Type 'typeof class' is not assignable to type 'ComponentType<any>'
我正在尝试使用 typescript 使用反应本机导航,并且在尝试连接我的屏幕时,我得到一个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;
}
}
这在组件 = {LoginScreen} 处失败。 我知道这是因为我的 React 组件“HomeScreen”不期待任何道具,但是处理这个问题的安全方法是什么,因为我看到了许多不同的解决方案。
我找到了我的问题的答案。 您可以使用https://reactnavigation.org/docs/1.x/navigation-prop/ ,其中包含有关如何处理这种确切情况的文档。 希望这可以帮助一些人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.