检查 `MaterialTopTabNavigator` 的渲染方法

Check the render method of `MaterialTopTabNavigator`

我想创建一个 Top Tab 导航器并将两个屏幕 Badges.js 和 Studying.js 放入 Tab 中,当我 运行 在我的设备上时我收到一条错误消息 "错误:元素类型无效:需要一个字符串..." and "检查`MaterialTopTabNavigator"的渲染方法.

TabScreen.js

import React from 'react';
import {View, Image, Text} from 'react-native';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';
import Badges from './Badge';
import Studying from './Studying';

const Tab = createMaterialTopTabNavigator();

const TabsScreen = () => {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Badges" component={Badges} />
      <Tab.Screen name="Studying" component={Studying} />
    </Tab.Navigator>
  );
};
export default TabsScreen;

Badges.js

import React from 'react';
import {View, Image, Text} from 'react-native';

const Badges = () => {
  return (
    <View>
      <Text>Badges</Text>
    </View>
  );
};

export default Badges;

Studying.js

import React from 'react';
import {View, Image, Text} from 'react-native';

const Studying = () => {
  return (
    <View>
      <Text>Studying</Text>
    </View>
  );
};

export default Studying;

我遇到了类似的问题。这是 mi 解决方案(npm 或 yarn 没问题)

a) 卸载更多更新版本 6.0.0

yarn remove react-navigation/material-top-tabs

b) 在我的例子中安装这个版本 5.3.15

yarn add @react-navigation/material-top-tabs@5.3.15

c) 停止并启动你的项目和工作

d) 继续看官方文档 https://reactnavigation.org/docs/material-top-tab-navigator/#example

确保以下所有包具有相同的版本

"@react-navigation/material-top-tabs": "^6.0.1",
"@react-navigation/native": "^6.0.1",
"@react-navigation/stack": "^6.0.1",