react-native - 类声明中类型参数少于 1 个的组件

标签 react-native react-navigation

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { createBottomTabNavigator, createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
import Event from './src/components/event/Event.js';
import Chat from './src/components/chat/Chat.js';
import Signup from "./src/components/signup/Signup.js";
import Verif1 from "./src/components/signup/Verif1.js";
import NewEvent from "./src/components/event/Newevent.js";
import EditUser from "./src/components/user/Edituser";
import NewUser from "./src/components/user/Newuser";
import io from 'socket.io-client';
import GLOBAL from "./src/lib/global";
import SplashScreen from "./src/components/splashscreen/SplashScreen";


const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

//socket.io
const socket = io(GLOBAL.BASE_URL, {
  //const socket = io(GLOBAL.BASE_URL, {
    transports: ['websocket'],
    jsonp: false
  });
console.log("socket id in App.js : ", socket.id);


socket.on('disconnect', (reason) => {
  // ...
  if (reason === 'io server disconnect') {
    // the disconnection was initiated by the server, you need to reconnect manually
    socket.connect();
  }
  // else the socket will automatically try to reconnect
});

const ChatWithSocket = (props) => (<Chat {...props} socket={socket} />)

const EventStack = {

    Event:  {
      screen: Event,
      navigationOptions: {
        title: 'Event',
      },
    },
    NewEvent: {
      screen: NewEvent,
      navigationOptions: {
        title: 'New Event',
      },
    },

    Chat: {
      screen: ChatWithSocket,
      navigationOptions: {
        title: 'Chat',
      },

    },

  };

const SignupStack = {
  Signup: {
    screen: Signup,
    navigationOptions: {
      title: 'Signup',
    },
  },
  Verif1: {
    screen: Verif1,
    navigationOptions: {
      title: 'Verify User',
    },
  },
};

const UserStack = { 
    NewUser: {
      screen: NewUser,
      navigationOptions: {
        title: 'New User',
      },
    },
    /* EditUser: {
      screen: EditUser,
      navigationOptions: {
        title: 'Edit User',
      },
    },     */

};


const bottomTabNavOptions =  {
  defaultNavigationOptions: ({ navigation }) => ({
    tabBarIcon: ({ focused, tintColor }) => {
      const { routeName } = navigation.state;
      console.log("Navigation : ", navigation.dangerouslyGetParent().getParam('params'));
      let iconName;
      if (routeName === 'Event') {
        iconName = `ios-information-circle${focused ? '' : '-outline'}`;
      } else if (routeName === 'User') {
        iconName = `ios-options${focused ? '' : '-outline'}`;
      }

      return <Text>Hello the world!</Text>
    },
  }),
  tabBarOptions: {
    activeTintColor: 'tomato',
    inactiveTintColor: 'gray',
  },
};

class App extends React.Component {  //<<<=== this line cause error

  EventRoute = (initRoute) => {
    createStackNavigator(EventStack, {
      initialRouteName: initRoute,
    })
  };

  UserRoute = (initRoute) => {
    createStackNavigator(UserStack, {
      initialRouteName: initRoute,
    })
  };


  bottomTabScreen = () => {
    //if there is a token and user
    if (this.props.token && this.props.user) {
    return createBottomTabNavigator(
      {
        Event: {screen: this.EventRoute("Event")},
        User: {screen: this.UserRoute("User")},
      }, bottomTabNavOptions
    );
    } else  {
    return createStackNavigator(
      {
        Signup: {screen: Signup},
        Verif1: {screen: Verif1},
      }
    );
    };
  };

  createDynamicRoutes = () => {
    return createAppContainer(
      createBottomTabNavigator(this.bottomTabScreen())
    );
  };

    render() {

      const AppContainer = this.createDynamicRoutes();
      return <AppContainer />;
    }
};

const InitialNavigator = createSwitchNavigator({
  Splash: SplashScreen,
  App: App,
});
export default createAppContainer(InitialNavigator);  

但是 class App extends React.Component {...} 的声明

显示 IDE VS Code 中的错误:

Cannot use  property `Component` [1] with fewer than 1 type argument.Flow(InferError)
react.js(26, 30): [1] property `Component`
Quick Fix...
Peek Problem

根据我对 React Native 0.59 的最新文档的阅读,class App extends React.Component {...} 很好。 React导航的版本是3.9。

最佳答案

看起来像流程验证错误,向您的组件添加空 Prop 。\

type Props = {};
export default class App extends Component<Props> {
 ...
}

关于react-native - 类声明中类型参数少于 1 个的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56431328/

相关文章:

react-native - 如何更改 expo-av 中的视频显示方向?

react-native - 如何同时实现堆栈导航和抽屉导航

javascript - 错误 : `createNavigationContainer()` has been removed. 请改用 `createAppContainer()`

android - 选择将在哪个 android 设备(模拟器或手机)上运行 react-native run-android

react-native - 在何处输入信息以解决以下提示 : "let us know if your app contains ads"

react-native - 没有那个文件或目录,在 React-Native 中打开 'app\build\intermediates\merged_manifests\debug\AndroidManifest.xml'

reactjs - 如何使用 react 导航预加载路线

javascript - React Native Navigation Error : The action navigate with payload {"name": 192. 168.100.189:1900 0", "params":{}} 未被任何导航器处理

android - 给定边框半径时如何设置标签栏的背景颜色?

reactjs - 使用 React-Navigation v4 延迟加载特定选项卡