带有 react-native 的 redux 不起作用——(0, _combineReducers.default) 不是一个函数
rudux with react-native dont work -- (0, _combineReducers.default) is not a function
我做的和react app完全一样,但是react可以用,react-native不行
app.js 文件
import React from 'react';
import { Provider } from 'react-redux';
import { store } from './redux/reducers/combineReducers'
var Stack = createNativeStackNavigator()
export default function App() {
return (<Provider store={store()}> // if i write store={store} error: undefined is not an object (evaulating 'store.getStare')
</Provider>
);
}
combinedReducers.js
import { key} from "./reducerKey";
import { combineReducers } from 'redux'
export var reducers = combineReducers({
storeKey: key,
})
reducerKey 文件
export var key = (state = 0, action) => {
if (action.type === 'changeKey') {
return action.playload
}
else {
return state
}
}
您没有创建 store
,而是试图导出 reducer
。
在combinedReducers.js
中:
import {createStore, combineReducers} from 'redux';
const rootReducer = combineReducers({
storeKey: key,
})
const store = createStore(rootReducer)
export {store}
现在在 App.js
中,您可以使用 store
(无需调用):
import {store} from 'path/to/store';
// rest of the codes ...
<Provider store={store}>
// rest of the codes ...
我做的和react app完全一样,但是react可以用,react-native不行
app.js 文件
import React from 'react';
import { Provider } from 'react-redux';
import { store } from './redux/reducers/combineReducers'
var Stack = createNativeStackNavigator()
export default function App() {
return (<Provider store={store()}> // if i write store={store} error: undefined is not an object (evaulating 'store.getStare')
</Provider>
);
}
combinedReducers.js
import { key} from "./reducerKey";
import { combineReducers } from 'redux'
export var reducers = combineReducers({
storeKey: key,
})
reducerKey 文件
export var key = (state = 0, action) => {
if (action.type === 'changeKey') {
return action.playload
}
else {
return state
}
}
您没有创建 store
,而是试图导出 reducer
。
在combinedReducers.js
中:
import {createStore, combineReducers} from 'redux';
const rootReducer = combineReducers({
storeKey: key,
})
const store = createStore(rootReducer)
export {store}
现在在 App.js
中,您可以使用 store
(无需调用):
import {store} from 'path/to/store';
// rest of the codes ...
<Provider store={store}>
// rest of the codes ...