React native 如何修复React本机元素类型无效:应为字符串或类/函数,但存在对象问题?

React native 如何修复React本机元素类型无效:应为字符串或类/函数,但存在对象问题?,react-native,react-native-android,React Native,React Native Android,我将尝试实现react本机推送通知: import React from 'react'; import { AppRegistry } from 'react-native'; import App from './app'; AppRegistry.registerComponent('PushNotificationHowTo', () => App); 这是我的密码: index.android.js: import React from 'react'; import { Ap

我将尝试实现react本机推送通知:

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './app';
AppRegistry.registerComponent('PushNotificationHowTo', () => App);
这是我的密码:

index.android.js:

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './app';
AppRegistry.registerComponent('PushNotificationHowTo', () => App);
/app/index.js

import React, { Component } from 'react';
import { View, Text, StyleSheet, Picker, AppState, Platform } from 'react-native';
import PushController from './PushController';
import PushNotification from 'react-native-push-notification';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  picker: {
    width: 100,
  },
});

export default class App extends Component {
  constructor(props) {
    super(props);

    this.handleAppStateChange = this.handleAppStateChange.bind(this);
    this.state = {
      seconds: 5,
    };
  }

  componentDidMount() {
    AppState.addEventListener('change', this.handleAppStateChange);
  }

  componentWillUnmount() {
    AppState.removeEventListener('change', this.handleAppStateChange);
  }

  handleAppStateChange(appState) {
    if (appState === 'background') {
      let date = new Date(Date.now() + (this.state.seconds * 1000));

      if (Platform.OS === 'ios') {
        date = date.toISOString();
      }

      PushNotification.localNotificationSchedule({
        message: "My Notification Message",
        date,
      });
    }
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Choose your notification time in seconds.
        </Text>
        <Picker
          style={styles.picker}
          selectedValue={this.state.seconds}
          onValueChange={(seconds) => this.setState({ seconds })}
        >
          <Picker.Item label="5" value={5} />
          <Picker.Item label="10" value={10} />
          <Picker.Item label="15" value={15} />
        </Picker>
        <PushController />
      </View>
    );
  }
}
import React, { Component } from 'react';
import PushNotification from 'react-native-push-notification';

export default class PushController extends Component {
  componentDidMount() {
    PushNotification.configure({
      onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );
      },
    });
  }

  render() {
    return null;
  }
}
在执行代码时,我得到了以下问题:

元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:object。


如何解决该问题以及如何实现推送通知???

您可以尝试删除``并运行吗?如果它运行,请尝试返回
而不是
null
@SagarKhatri删除“`您使用的是哪个版本的RN?”依赖项时会出现相同的错误:{“react”:“15.4.2”,“react native”:“0.42.3”,“react native push notification”:“^2.2.1”}@SagarKhatri您需要一步一步地调试组件。尝试仅在应用程序渲染中返回
,然后逐个添加组件。是否可以尝试删除``并运行?如果它运行,请尝试返回
而不是
null
@SagarKhatri删除“`您使用的是哪个版本的RN?”依赖项时会出现相同的错误:{“react”:“15.4.2”,“react native”:“0.42.3”,“react native push notification”:“^2.2.1”}@SagarKhatri您需要一步一步地调试组件。尝试仅在应用程序渲染中返回
,而不是逐个添加组件。