Я создаю приложение React / Redux. После настройки моего магазина состояние возвращается как «неопределенное». Начальное состояние в магазине пустое, но оба редуктора имеют начальное состояние. Инструменты реагировать на разработки работают, но состояние не меняется.
// Приложение. js
function App() {
return (
<Provider store={store}>
<Router>
<div>
<Navbar />
<Switch>
<Route exact path='/' component={Home} />
<Route exact path='/subscriptions' component={Subscriptions} />
<Route exact path='/login' component={Login} />
<Route exact path='/register' component={Register} />
<Route exact path='/dashboard' component={Dashboard} />
</Switch>
<Footer />
</div>
</Router>
</Provider>
);
}
export default App;
// Store. js
import { createStore, applyMiddleware, compose } from 'redux'; // Compose is brought in so that we can combine the reducer with what is required by chrome to add the Redux extension
import thunk from 'redux-thunk'; // Middleware
import rootReducer from './reducers/index'; // Step 1. This is where we will combine all other reducers and be able to bring it into one file as clean as possible
const initialState = {}
// Step 2
// Create the store
const store = createStore(
rootReducer,
initialState,
compose(applyMiddleware(thunk))
);
// Exporting the store to bring into main App.js file and be able to use across the entired app.
export default store;
Редукторы /index.js
import { combineReducers } from 'redux';
import authReducer from './authReducer';
import errorReducer from './errorReducer';
export default combineReducers({
auth: authReducer,
errors: errorReducer
});
Действия / типы. js
export const GET_ERRORS = 'GET_ERRORS';
export const SET_CURRENT_USER = 'SET_CURRENT_USER';