reactjs - 正确的组件已通过但 React Native 错误:元素类型无效:预期为字符串或类/函数,但得到:未定义
问题描述
请参阅下面的错误我在我的 React Native 项目中得到
ERROR Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: 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.
Check your code at MaterialTopTabView.tsx:51.
in MaterialTopTabView (at createMaterialTopTabNavigator.tsx:44)
in MaterialTopTabNavigator (at AuthTabs.js:14)
看截图
请参阅下面的代码
AuthTabs.js
import React from 'react';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';
import SignIn from './tabs/SignIn';
import SignUp from './tabs/SignUp';
const Tab = createMaterialTopTabNavigator();
export default function AuthTabs() {
return (
<Tab.Navigator>
<Tab.Screen
name="SignIn"
component={SignIn}
options={({}) => ({
tabBarLabel: 'Sign In',
})}
/>
<Tab.Screen
name="SignUp"
component={SignUp}
options={({}) => ({
tabBarLabel: 'Sign Up',
})}
/>
</Tab.Navigator>
);
}
登入
import React from 'react';
import {View, Text} from 'react-native';
export default function SignIn() {
return (
<View>
<Text>Singn In Screen</Text>
</View>
);
}
报名
import React from 'react';
import {View, Text} from 'react-native';
export default function SignUp() {
return (
<View>
<Text>Sign Up Screen </Text>
</View>
);
}
我已经检查了所有类似的问题,但在任何地方都没有合适的解决方案请告诉我如何解决这个问题谢谢
解决方案
也许您的材料顶部选项卡的主要版本与反应导航不一致。
如果您使用的是 5.x,请运行此命令
yarn add @react-navigation/material-top-tabs@^5.x react-native-tab-view@^2.x
或者你可以将 react-navigation 升级到 6.x
推荐阅读
- angular - 没有statusText问题的Chrome错误代码
- php - 为什么 Post 请求在使用 codeigniter 4 的服务器上不起作用?
- python - 如何使用 docker 文件将名称服务器添加为 echo nameserver 8.8.8.8 >> /etc/resolv.conf
- python - 如何使列重复值唯一?
- php - 基于行和列的 Mpdf 分页符
- javascript - 数据表垂直滚动到特定的行 id
- python - 将 Selenium 与 chromedriver (Python) 一起使用时出现对象不可调用错误
- angularjs - 如何在 AngularJS 中自定义输入字段长度?
- java - 将(自定义)解码器添加到 WebMVC 端点
- python - 删除在 1 列中总和为零但在熊猫中重复的行