[英]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.