Javascript 反应本机组件未安装

Javascript 反应本机组件未安装,javascript,react-native,react-native-android,Javascript,React Native,React Native Android,我目前正在开发一个react本机应用程序,其中我们使用react“组件”(它不显示任何内容,只是充当调度器)以JavaScript完成一些一次性请求。JS代码非常简单: import React from 'react' import { AppRegistry, DeviceEventEmitter } from 'react-native' class NativeEventDispatcher extends React.Component { constructor() {

我目前正在开发一个react本机应用程序,其中我们使用react“组件”(它不显示任何内容,只是充当调度器)以JavaScript完成一些一次性请求。JS代码非常简单:

import React from 'react'
import { AppRegistry, DeviceEventEmitter } from 'react-native'

class NativeEventDispatcher extends React.Component {
  constructor() {
    super()
    console.log("anyone home?")
  }
  componentDidMount() {
    DeviceEventEmitter.addListener('DoSomething', () => {})
  }
  render() {
    return null
  }
}

AppRegistry.registerComponent('NativeEventDispatcher', () => NativeEventDispatcher);
然而,由于某种原因,在打电话之后

val rootView = ReactRootView(context)
rootView.startReactApplication(reactInstanceManager, "NativeEventDispatcher", null)
addContentView(rootView, ViewGroup.LayoutParams(0, 0))
reactInstanceManager.onHostResume(this, this)
什么也没发生。组件没有挂载,JS文件中没有断点被执行,构造函数中的日志永远不会打印。几乎就好像组件装载正在悄无声息地失败


以前有人遇到过这种情况吗?有可能的解决方案吗?我已经试着调试了一天左右,但运气不好。

我不知道第二个东西,但我会像这样写第一个

import React, { Component } from 'react';
import { View, AppRegistry, DeviceEventEmitter } from 'react-native';

class NativeEventDispatcher extends Component {
    constructor(props) {
        super(props)
        console.log("anyone home?")
    }
    componentDidMount() {
        DeviceEventEmitter.addListener('DoSomething', () => {})
    }
    render() {
        return (
            <View></View>
        );
    }
}

export default NativeEventDispatcher;

AppRegistry.registerComponent('NativeEventDispatcher', () => NativeEventDispatcher);
import React,{Component}来自'React';
从“react native”导入{View、AppRegistry、DeviceEventEmitter};
类NativeEventDispatcher扩展组件{
建造师(道具){
超级(道具)
console.log(“有人在家吗?”)
}
componentDidMount(){
DeviceEventEmitter.addListener('DoSomething',()=>{})
}
render(){
返回(
);
}
}
导出默认NativeEventDispatcher;
AppRegistry.registerComponent('NativeEventDispatcher',()=>NativeEventDispatcher);

您应该使用导出默认值导出类

这段代码在
index.android.js
中,因为我们仍在验证这一点。但是是的,在一个单独的模块中,我们必须导出它。话虽如此,我仍然不知道将
returnnull
更改为
return
会起到什么作用。构造函数甚至没有被调用,因此render方法不应该与它有太多关系。