react-redux错误不能将类作为函数调用

时间:2017-11-03 08:21:17

标签: reactjs react-redux

我一直在学习react-redux,当我尝试连接我的react组件时,我收到以下错误。

connect.js:41 Uncaught (in promise) TypeError: Cannot call a class as a function
at _classCallCheck (connect.js:41)
at Connect (connect.js:125)
at eval (combineReducers.js:37)
at Array.forEach (<anonymous>)
at eval (combineReducers.js:34)
at Map.withMutations (immutable.js:1355)
at eval (combineReducers.js:33)
at computeNextEntry (<anonymous>:2:27469)
at recomputeStates (<anonymous>:2:27769)
at <anonymous>:2:31382 

我正在使用react-redux version 4.4.8react-boilerplate。我使用的代码是

import React from 'react';
import { connect } from 'react-redux';

 class Something extends React.Component {

 render(){
 return(
       <div>
          <p>It is working</p>
       </div>
      );
    }
  }

 export default connect()(Something);

我在这里缺少什么?任何帮助将不胜感激,因为我无法弄清楚这个问题。

**修改

我从路线中移除了对Reducer的引用并且它有效。也许路线有问题。

 {
  path: '/something',
  name: 'something',
  getComponent(nextState, cb) {
    const importModules = Promise.all([
      import('./Something'),
    //  import('./Something/reducer')
    ]);

    const renderRoute = loadModule(cb);

    importModules.then(([component]) => {
      //injectReducer('something', reducer.default);
        renderRoute(component);
    });
    importModules.catch(errorLoading);
  },

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。问题是数组importModules中的元素顺序。然后(([component,reducer])应该与reducer和component的import语句相同。正如你在下面的代码中看到的那样。所以问题是与{ path: '/something', name: 'something', getComponent(nextState, cb) { const importModules = Promise.all([ import('./Something'), import('./Something/reducer') ]); const renderRoute = loadModule(cb); importModules.then(([component, reducers]) => { injectReducer('something', reducer.default); renderRoute(component); }); importModules.catch(errorLoading); },

相关
import tkinter as tk

class Selections(tk.Frame): 
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)

    self.FifthLabelLeft = tk.Label(self,
                     text="""Riding""",
                     justify = tk.CENTER,
                     padx = 10).grid(row=4, column = 0, pady=5)

    self.FifthLabelCenter = tk.Label(self,
                     text="""Winning Candidate""",
                     justify = tk.CENTER,
                     padx = 10).grid(row=4, column = 1, pady=5)

    self.FifthLabelRight = tk.Label(self,
                     text="""Percent of Vote""",
                     justify = tk.CENTER,
                     padx = 10).grid(row=4, column = 2, pady=5)

    mybox = tk.LabelFrame(self, padx=5, pady=4)
    mybox.grid(row=5, column=0, columnspan=3)

    canvas = tk.Canvas(mybox, borderwidth=5, background="#70ff33")
    frame = tk.Frame(canvas, background="#33f4ff")
    vsb = tk.Scrollbar(mybox, orient="vertical", command=canvas.yview)
    canvas.configure(yscrollcommand=vsb.set, width=450, heigh=50)       

    vsb.pack(side="right", fill="y")
    canvas.pack(side="left", fill="both", expand=True)
    canvas.create_window((4,4), window=frame, anchor="nw", tags="frame")

    # be sure that we call OnFrameConfigure on the right canvas
    frame.bind("<Configure>", lambda event: self.OnFrameConfigure(canvas))

    self.fillWindow(frame)

    self.QuitButton = tk.Button(self, 
                                text="QUIT", 
                                command=root.destroy, 
                                padx=25, pady=0)
    self.QuitButton.grid(column = 0, columnspan=3)


def fillWindow(self, frame): 
    PartyWinnersList = [['Some list of places', "Somebody's Name", 0.37448599960838064], 
                        ['A shorter list', 'Three Long Names Here', 0.52167817821240514],
                        ['A much longer, longer entry', 'Short Name', 0.41945832387008858]]
    placement = 2
    for i in PartyWinnersList:
        ShowYear = tk.Label(frame,
                                  text="""%s """ % i[0]
                                  )
        ShowYear.grid(row=placement, column = 0, sticky=tk.S)
        ShowSystem = tk.Label(frame,
                                  text="""%s """ % i[1]
                                  )
        ShowSystem.grid(row=placement, column = 1, sticky=tk.N)
        PercentVotes = i[2]*100
        ShowVotes = tk.Label(frame,
                                  text="""%3.1f""" % PercentVotes
                                  )
        ShowVotes.grid(row=placement, column = 2, sticky=tk.N)
        placement += 1

def OnFrameConfigure(self, canvas):
    canvas.configure(scrollregion=canvas.bbox("all"))

if __name__ == "__main__": 
    root = tk.Tk()
    main = Selections(root)
    main.pack(side="top", fill="both", expand=True)
    root.mainloop()