简体   繁体   English

每当我使用 props.navigation.navigate('Game') 时,在 HeaderBackButton.tsx 中反应本机导航问题

[英]React native navigation problem in HeaderBackButton.tsx whenever I use props.navigation.navigate('Game')

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.警告:React.createElement:类型无效 - 需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:%s.%s%s,未定义,您可能忘记导出您的来自定义它的文件中的组件,或者您可能混淆了默认导入和命名导入。

Check your code at HeaderBackButton.tsx:152.在 HeaderBackButton.tsx:152 检查您的代码。

My code is the following:我的代码如下:

 const Home: FunctionComponent<HomeProps> = (props: HomeProps) => { return ( <View style={styles.container}> <View> <Text>{"Listo para jugar Cuarenta? "}</Text> </View> <View style={styles.button}> <Button title="Rules" onPress={() => { console.log("Props", props); props.navigation.navigate('Cuarenta'); }}/> </View> <View style={styles.button}> <Button title="New Game" onPress={() => { props.navigation.navigate('Game'); }}></Button> </View> <View style={styles.button}> <Button title="Tablero" onPress={() => { props.navigation.navigate('Tablero'); }}></Button> </View> <View style={styles.button}> <Button title="Robot" onPress={() => { props.navigation.navigate('RobotScene'); }}></Button> </View> </View> ) }

 export default function App() { return ( <NavigationContainer> <Stack.Navigator screenOptions={{ headerStyle: { backgroundColor: '#f41e9e', }, headerTintColor: '#fff', headerTitleStyle: { fontWeight: 'bold', }, }} > <Stack.Screen name='Home' component={Home} options={{title: 'Juego de Cuarenta'}} /> <Stack.Screen name='Cuarenta' component={Cuarenta} /> <Stack.Screen name='Game' component={GameScene} /> <Stack.Screen name='Tablero' component={Tablero} /> <Stack.Screen name='RobotScene' component={RobotScene} /> </Stack.Navigator> </NavigationContainer> ); }

I solve this by rolling back to expo 38.0.8(the original version of my project).我通过回滚到 expo 38.0.8(我的项目的原始版本)来解决这个问题。

I ran into the same problem updating react-navigation :我在更新react-navigation遇到了同样的问题:

@react-navigation/native  ^5.7.2  →  ^5.7.3
@react-navigation/stack   ^5.8.0  →  ^5.9.0

Reverting back fixes the problem for now.恢复现在可以解决问题。

In my case the new version (5.7.2+?) of @react-navigation/stack was the reason.在我的情况下,@react-navigation/stack 的新版本(5.7.2+?)是原因。 So just run npm i @react-navigation/stack@5.7.1 for fix it所以只需运行 npm i @react-navigation/stack@5.7.1 来修复它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native props.navigation.navigate 不是 object - React Native props.navigation.navigate is not an object React Native:undefined 不是对象(评估“props.navigation.navigate”) - React Native: undefined is not an object (evaluating 'props.navigation.navigate') undefined 不是 object (评估'props.navigation.navigate'),同时实现反应本机导航 - undefined is not an object (evaluating 'props.navigation.navigate') while implementing react native navigation 我在本机反应中与此this.props.navigation.navigate有问题 - I am having issues with this.props.navigation.navigate in react native 反应本机导航(未定义不是对象.. this.props.navigation.navigate - React native navigation (undefined is not an object .. this.props.navigation.navigate React Native - 导航问题“未定义不是对象(this.props.navigation.navigate)” - React Native - navigation issue “undefined is not an object (this.props.navigation.navigate)” undefined 不是对象 this.props.navigation.navigate 反应原生 - undefined is not an object this.props.navigation.navigate react native React Native:undefined不是对象(评估&#39;_this2.props.navigation.navigate&#39;) - React Native : undefined is not an object (evaluating'_this2.props.navigation.navigate') 【React-native】undefined不是对象(评估&#39;_this.props.navigation.navigate&#39;) - 【React-native】undefined is not an object (evaluating '_this.props.navigation.navigate') undefined 不是一个对象(评估&#39;this.props.navigation.navigate&#39;)-React Native - undefined is not an object (evaluating 'this.props.navigation.navigate') - React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM