繁体   English   中英

使用 React.js 存储错误 - TypeError: Object(...) is not a function react

[英]Store error using React.js - TypeError: Object(...) is not a function react

我正在尝试做我的 SPA 商店。 我制作了我需要的每件事的减速器,但是当我呈现页面时,我收到了这条消息

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 | 导出默认 createStore(rootReducers,composeWithDevtools(applyMiddleware(thunk)))

减速器.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
}

商店.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)))

尝试将对象传递给 combineReducers 并在所有减速器之前给出名称。 combineReducers({ reducerName: reducerFunction });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM