javascript - TypeError:store.getState 不是函数。(在'store.getState()'中,'store.getState'未定义我该如何解决这个问题?
问题描述
我想连接 redux-saga witdh react-native 但这个错误不断发生......
TypeError:store.getState 不是函数。(在 'store.getState()' 中,'store.getState' 未定义
警告:失败的道具类型:
store
提供function
给的道具类型无效Provider
,预期object
这是我的代码
(index.js)
import {AppRegistry} from 'react-native';
import Root from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => Root);
(应用程序.js)
import React from 'react';
import Store from './store/configureStore'
import {Provider} from 'react-redux';
import {App} from './src/index';
const Root = () => {
return (
<Provider store={Store}>
<App />
</Provider>
);
};
export default Root;
(src/index.js)
import React from 'react';
import Navigator from './Screens/Navigator';
import styled from 'styled-components/native';
const App = ({}) => {
return (
<Navigator/>
);
};
export {App};
(商店/cofigurestore.js)
import { applyMiddleware, createStore, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { composeWithDevTools } from 'redux-devtools-extension';
import reducer from '../reducers';
import rootSaga from '../sagas';
const Store = () => {
const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware];
const enhancer = process.env.NODE_ENV === 'production'
? compose(applyMiddleware(...middlewares))
: composeWithDevTools(
applyMiddleware(...middlewares),
);
const store = createStore(reducer, enhancer);
store.sagaTask = sagaMiddleware.run(rootSaga);
return store;
};
export default Store;
(减速器/index.js)
import { combineReducers } from 'redux';
import user from './user';
import post from './post';
// (이전상태, 액션) => 다음상태
const rootReducer = (state, action) => {
switch (action.type) {
// case HYDRATE:
// // console.log('HYDRATE', action);
// return action.payload;
default: {
const combinedReducer = combineReducers({
user,
post,
});
return combinedReducer(state, action);
}
}
};
export default rootReducer;
(圣人/index.js)
import { all, fork } from 'redux-saga/effects';
import axios from 'axios';
import postSaga from './post';
import userSaga from './user';
export default function* rootSaga() {
yield all([
fork(postSaga),
fork(userSaga),
]);
}
请帮助我.........我想解决这个问题......但我不知道我该怎么做
解决方案
在您App.js
身上,您应该将调用Store
函数的结果传递给Provider
而不是函数本身。
const Root = () => {
return (
<Provider store={Store()}>
<App />
</Provider>
);
};
推荐阅读
- python - Pandas Groupby 除了列并取该列的第一个值
- python - 有没有办法恢复 anaconda3 包含文件?
- python - Python Selenium:如何返回给定 URL 的所有 XPath 列表
- html - HTML:如何使用页面中文本的内部链接?
- node.js - 无头 Chrome 浏览器无法在 Windows 容器上启动?
- javascript - 如何使用 Node.js 检索内容中不包含特定字符串的文件
- javascript - 值作为字符串分配给对象,即使它是强类型的
- php - 在 Magento 2 中开票,得到“我们现在无法保存发票”和“回滚交易尚未正确完成”
- python - 为什么 nohup 在 os.system 中的 python 脚本中不起作用?
- php - 如何使用 OneToMany 关系上的内置计数约束来验证新的子实体?