React Native新手求助:使用createMaterialBottomTabNavigator遇函数无效警告
Hey there! That warning is super common when you accidentally treat a function like a React component the wrong way—let's walk through how to fix this for your tab navigator setup.
Common Causes & Fixes
The error pops up because React is trying to render a function directly instead of rendering the component that function creates. Here are the two most likely issues in your code:
1. Incorrectly calling your component in the navigator config
If you wrote something like screen: Home() instead of screen: Home in your tab routes, you're executing the component function immediately (returning raw JSX) instead of passing the component itself to the navigator. That's an easy mistake to make!
2. Rendering the navigator function instead of the component
If you're trying to use your tab navigator in your app like {TabNavigator} instead of <TabNavigator/>, React sees the function itself as a child element—which it can't render properly.
Correct Example Code
Let's put it all together with your imports and a proper navigator setup:
import { createMaterialBottomTabNavigator } from 'react-navigation-tabs'; import Home from '../Screens/HomeScreen/Home'; import Maps from '../Screens/HomeScreen/Maps'; import My from '../Screens/HomeScreen/My'; // Fix the import path for Subjects (you had a partial path with `Screen` instead of `Screens`) import Subjects from '../Screens/HomeScreen/Subjects'; // Create the tab navigator with proper route configs const TabNavigator = createMaterialBottomTabNavigator( { Home: { screen: Home, // Pass the component reference, don't call it! }, Maps: { screen: Maps, }, My: { screen: My, }, Subjects: { screen: Subjects, }, }, { // Optional: Add your tab bar styling here initialRouteName: 'Home', activeColor: '#ffffff', barStyle: { backgroundColor: '#2196F3' }, } ); export default TabNavigator;
Then, when using this navigator in your root app component, make sure to render it as a component:
import TabNavigator from './path/to/your/TabNavigator'; export default function App() { return ( // Use the component tag, not the function reference directly <TabNavigator /> ); }
Quick Checks to Verify
- Double-check all your component imports: Ensure paths are correct (your
Subjectsimport had a partial path—make sure it points to the right file) - Never call your components with
()in the navigator'sscreenfield - Always render components with angle brackets
<ComponentName/>when using them in JSX
内容的提问来源于stack exchange,提问作者황정욱

