Reputation: 163
im trying to do the store of my SPA. I made the reducers of each thing i will need, but when i rendered the page i received this message
TypeError: Object(...) is not a function Module../src/redux/store.js C:/Users/Mycomputer/Desktop/Projects/React/2020_03_29_workshop/src/redux/store.js:13
13 | export default createStore(rootReducers,composeWithDevtools(applyMiddleware(thunk)))
reducers.js
import { GET_ALL_POSTS, GET_ALL_SPECIALITIES, GET_ALL_COURSES, GET_ALL_TEACHERS,
GET_POST, GET_SPECIALITY, GET_LESSON, GET_COURSE } from "./actions"
export const postReducer = (state = {}, action) => {
if(action.type === GET_ALL_POSTS){
return {
...state,
posts: action.posts
}
}
if(action.type === GET_POST){
return {
...state,
post: action.post
}
}
return state
}
export const specialityReducer = (state = {}, action) => {
if(action.type === GET_ALL_SPECIALITIES){
return {
...state,
specialities: action.specialities
}
}
if(action.type === GET_SPECIALITY)
return {
...state,
speciality: action.speciality
}
return state
}
export const courseReducer = (state = {}, action) => {
if (action.type === GET_ALL_COURSES){
return {
...state,
courses: action.courses
}
}
if (action.type === GET_COURSE){
return {
...state,
course: action.course
}
}
return state
}
export const teacherReducer = (state = {}, action) => {
if(action.type === GET_ALL_TEACHERS){
return {
...state,
teachers: action.teachers
}
}
return state
}
export const lessonReducer = (state = {}, action) => {
if (action.type === GET_LESSON){
return {
...state,
lesson: action.lesson
}
}
return state
}
store.js
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { composeWithDevtools } from 'redux-devtools-extension'
import thunk from 'redux-thunk'
import { postReducer,
specialityReducer,
courseReducer,
teacherReducer,
lessonReducer
} from './reducers'
export default createStore(combineReducers({postReducer, specialityReducer, courseReducer, teacherReducer, lessonReducer}),composeWithDevtools(applyMiddleware(thunk)))
Upvotes: 0
Views: 339
Reputation: 1565
Try to pass object to combineReducers and give name before all reducers. combineReducers({ reducerName: reducerFunction });
Upvotes: 0