休言女子非英物,夜夜龙泉壁上鸣。这篇文章主要讲述Redux connect - 模块AppRegistry不是注册的可调用模块相关的知识,希望能为你提供帮助。
我在启动一个新项目并实现redux和react-navigation后收到此错误Module AppRegistry is not a registered callable module
。
调试器逐步完成我的代码的初始化,但我无法看到抛出更具描述性的错误的位置。我唯一看到的是调试时确实没有调用runApplication
的方法。由于react-redux
,我的设置与默认的AppRegistry不同。
import React from 'react'
import { Provider } from 'react-redux';
import configureStore from './store';
import AppReducer from './reducers';
import { persistStore } from 'redux-persist'
import AppWithNavigationState from './navigator'export default class App extends React.Component {
store = configureStore(AppReducer);
constructor(props) {
super(props);
persistStore(this.store).purge();
}render() {
return <
Provider store={this.store}>
<
AppWithNavigationState />
<
/Provider>
}
}
据我所知,没有必要注册我的App类,也不需要使用
AppRegistry
手动注册我的组件。我觉得我的代码应该受到责备,因为之前曾经有过工作,但堆栈跟踪并没有指向任何东西。当然,当添加
AppRegistery.registerComponent
时,它的工作原理!但这并不能解释为什么以前没有必要这样做。我的
AppNavigator
课程:import React from 'react'
import {
BackHandler,
} from 'react-native'
import {
addNavigationHelpers,
StackNavigator,
} from 'react-navigation'
import { connect } from 'react-redux'import Start from './components/start'
import Login from './components/login'
import AppCamera from './components/camera'export const AppNavigator = StackNavigator({
Start: {
screen: Start,
navigationOptions: {
title: 'App',
},
},
Login: {
screen: Login,
navigationOptions: {
title: 'Login',
}
},
Camera: {
screen: AppCamera,
navigationOptions: {
title: 'Camera',
}
}}, {
mode: 'modal',
headerMode: 'none',
});
// const AppWithNavigationState = ({ dispatch, nav }) =>
(
//<
AppNavigator navigation={addNavigationHelpers({ dispatch, state: nav })} />
// );
export class AppWithNavigationState extends React.Component {
constructor(props) {
super(props);
}componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', function() {
const { dispatch, navigation, nav } = this.props;
if (nav.routes.length === 1 &
&
(nav.routes[0].routeName === 'Login' || nav.routes[0].routeName === 'Start')) {
return false;
}
// if (shouldCloseApp(nav)) return false
dispatch({ type: 'Navigation/BACK' });
return true;
}.bind(this));
}componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress');
}render() {
return <
AppNavigator navigation={addNavigationHelpers({ dispatch: this.props.dispatch, state: this.props.nav })} />
}
}AppWithNavigationState.propTypes = {
dispatch: React.PropTypes.func.isRequired,
nav: React.PropTypes.object.isRequired,
auth: React.PropTypes.object.isRequired,
};
const mapStateToProps = state =>
({
nav: state.nav,
auth: state.auth,
});
export default connect(mapStateToProps)(AppWithNavigationState);
答案只需终止所有节点进程并启动npm服务器并运行应用程序:
Step1:运行命令killall -9 node
Step2:运行命令npm start
【Redux connect - 模块AppRegistry不是注册的可调用模块】Step3:运行命令react-native run-ios或react-native run-android
推荐阅读
- Android React Native卡在闪屏上
- 在ReactNative的Android应用程序中缓慢动画
- 我可以使用哑组件作为我的顶级组件与React / Redux App吗()
- 没有服务器的React app
- XAMPP-WAMPP PHP-SSL证书错误(unable to get local issuer certificate)
- 如何在Symfony 3中访问Rest API
- 如何在C#和WinForms中操作和使用JSON
- 如何在Winforms应用程序中使用CefSharp(Chrome嵌入式框架c#)
- 如何在Windows中使用PuTTY在远程服务器(Linux和Ubuntu)上执行.sh脚本