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

Posted

技术标签:

【中文标题】使用 React.js 存储错误 - TypeError: Object(...) is not a function react【英文标题】:Store error using React.js - TypeError: Object(...) is not a function react 【发布时间】:2020-07-11 14:59:07 【问题描述】:

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

TypeError: Object(...) 不是函数 模块../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)))

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)))

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于使用 React.js 存储错误 - TypeError: Object(...) is not a function react的主要内容,如果未能解决你的问题,请参考以下文章

带有 React.js 错误的 jQuery UI 可排序

如何解决 redux-persist 创建同步存储失败。回退到 React.js 中的 noop 存储

iPhone应用程序的React js问题(字符串和日期错误)[重复]

如何使用 CKEditor 和 React JS 捕获 OnChange 事件

GO语言Error处理

React.js Chrome 扩展 - 如何将 Background.js 中的数据存储在 React 内部的变量中?