【问题标题】:Getting this error on compiling through webpack Unexpected token, expected ","通过 webpack 编译时出现此错误 Unexpected token, expected ","
【发布时间】:2020-03-16 05:39:32
【问题描述】:

在编译此代码时,我收到此错误 SyntaxError: Unexpected token, expected ","。我希望你能帮我解决这个问题。在线出错(13:39)

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import rootReducers from './reducers';

const initialState = {};

const middleware = [thunk];

const store = createStore({
    rootReducers,
    initialState,
    composeWithDevTools(applyMiddleware(...middleware))
});

export default store;

谢谢

【问题讨论】:

  • composeWithDevTools(applyMiddleware(...middleware))这一行之后添加comma ,
  • 这不是语法错误

标签: reactjs redux react-redux redux-thunk redux-devtools-extension


【解决方案1】:

您对createStore 的呼叫是错误的。它应该是参数列表,而不是对象:

const store = createStore(rootReducers, initialState, composeWithDevTools(applyMiddleware(...middleware)));

正确的函数签名是:

 createStore(reducer, [preloadedState], [enhancer])

请参阅文档here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-29
    • 2016-03-19
    • 2020-01-15
    • 1970-01-01
    • 2020-10-12
    • 2019-02-13
    • 2015-10-16
    • 1970-01-01
    相关资源
    最近更新 更多