Всем привет,
так до конца и не понял как использовать combineReducers в redux.
Прочитал документацию, погуглил.
Большую часть понял, но выводит ошибку
Unexpected keys "checkLogged", "isLogged", "user", "isAdmin", "lotteries", "categories", "tickets"
found in preloadedState argument passed to createStore.
Expected to find one of the known reducer keys instead: "authorizationReducer", "userReducer", "categoriesReducer", "adminCategoriesReducer", "adminTicketsReducer".
Unexpected keys will be ignored.
всё что я понял что мои свойства(начальное состояние) не передаются
код :
store.js
import {createStore} from 'redux';
import reducer from './reducers/rootReducer.js';
const initialState = {
checkLogged : false,
isLogged : false,
user : false,
isAdmin : false,
lotteries : {},
categories : {},
tickets : {}
}
const store = createStore(reducer, initialState);
export default store;
rootReducer.js
import {combineReducers} from 'redux';
import authorizationReducer from './authorization/authorizationReducer.js';
import userReducer from './profile/userReducer.js';
import categoriesReducer from './lotteries/categoriesReducer.js';
import ticketsReducer from './tickets/ticketsReducer.js';
import adminCategoriesReducer from './admin/lotteries/categoriesReducer.js';
import adminTicketsReducer from './admin/tickets/ticketsReducer.js';
const reducer = combineReducers({
authorizationReducer,
userReducer,
categoriesReducer,
ticketsReducer,
adminCategoriesReducer,
adminTicketsReducer
})
export default reducer;
пример редуктора(подредуктора)
./ticketsReducer
function reducer(state, action){
switch (action.type) {
case 'EDIT_TICKET_PRICE' : {
return{
...state,
tickets : {
...state.tickets,
[action.name] : action.ticket
}
}
}
default : return state
}
}
export default reducer;
Праильно ли я вообще сделал