i made exactly same like in react app, but in react is working, in react-native doesnt work
app.js file
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 file
export var key = (state = 0, action) => {
if (action.type === 'changeKey') {
return action.playload
}
else {
return state
}
}
CodePudding user response:
You didn't create the store
instead you are trying to export the reducer
.
In the combinedReducers.js
:
import {createStore, combineReducers} from 'redux';
const rootReducer = combineReducers({
storeKey: key,
})
const store = createStore(rootReducer)
export {store}
Now in the App.js
, you can use the store
(without calling it):
import {store} from 'path/to/store';
// rest of the codes ...
<Provider store={store}>
// rest of the codes ...