【发布时间】:2017-05-16 19:51:55
【问题描述】:
我有一个扩展 react.component 的类。另一个类从这个类扩展并连接到一个 redux-store。
import React from 'react'
class A extends React.Component{
constructor(props){super(props); ...}
...
}
import React from 'react'
import {connect} from 'react-redux'
@connect(store=>{...})
class B extends A{
constructor(props){super(props); ...}
...
}
class C extend A{....}
不幸的是,这不起作用。难道不显式扩展 React.Component 就可以将类连接到商店吗?
错误:
Uncaught TypeError: Super expression must either be null or a function, not undefined
【问题讨论】:
-
这似乎应该可以工作。您能否提供更多关于正在发生或未发生的事情的信息?
-
你应该避免在组件之间做继承,最好只从 React.Component 继承
-
例如:我有几个列表组件,并且都共享相同的行为(处理程序等)。为什么我不应该将此函数导出到我扩展并仅添加渲染函数的组件中。 (我找不到合适的设计模式)
-
问题不正常,请看我的回答