我正在尝试使用 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/