javascript - React Native TypeError store.getState 不是函数
问题描述
大家好,我正在努力使我的代码更具可读性和实用性。
在 React Native 中使用 redux-saga 我遇到了一些问题。
当我尝试加载应用程序时,出现错误:
TypeError:store.getState 不是函数
此错误位于:
in Connect(Reprov) (at App.js:17) in RCTView (at View.js:44) in Provider (at App.js:14) in App (at renderApplication.js:34) in RCTView (at View.js:44) in RCTView (at View.js:44) in AppContainer (at renderApplication.js:33)
src/store/configureStore.js
import {createStore, applyMiddleware} from 'redux'
import createSagaMiddleware from 'redux-saga';
import rootReducer from '../reducers';
import rootSaga from '../sagas';
export default function () {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
rootReducer,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(rootSaga)
return store;
}
src/App.js
import React, {Component} from 'react'
import { View } from 'react-native';
import { Provider } from 'react-redux';
import AppNavigation from './Navigation';
import store from './store/configureStore';
import Reproof from './screens/Reprov';
import Approval from './screens/Aprov';
import PushNotificationController from './components/Push';
class App extends Component {
render() {
return (
<Provider store={store}>
<View style={{ flex: 1 }}>
<AppNavigation />
<Reproof />
<Approval />
<PushNotificationController />
</View>
</Provider>
)
}
}
export default App;
我不知道我做错了什么......
解决方案
您正在将商店作为变量导入,并且在文件中,它是一个函数:
import store from './store/configureStore';
试试这个 :
import configureStore from './store/configureStore';
然后创建一个变量存储
const store = configureStore();
推荐阅读
- vue.js - Vuejs 和 FilePond 文件不工作。如何将加载的文件传输到对象?
- algorithm - 什么是协调度和条件确定度?
- dax - 关于计算上一季度与当前季度之间差异的问题
- java - 队列中的 null 和 isEmpty() 有什么区别
- spring - Spring Cloud Stream Kafka - 方法必须是声明性的
- latex - 在空白不敏感环境/Z-Notation Schema 中格式化 Latex 中的字符串
- angularjs - 在 AngularJS 和 restangular 中调用 rest API
- python - 如何修复 KeyError:mycode 中的 0
- sql - 计算sql中远程和本地集之间的差异
- python - re.sub 将模板转换为函数