我有一個擴展react.component的類。另一類從這個類擴展並連接到一個redux-store。從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
_seems_喜歡它應該工作。你能給更多的信息是什麼或沒有發生? – markerikson
你應該避免在組件之間進行繼承,從React.Component中繼承它被認爲是一種好的做法。 –
例如:我有幾個列表組件,並且它們都共享相同的行爲(處理程序等)。爲什麼我不應該將這個函數導出到我擴展並添加渲染函數的組件中。 (我找不到合適的設計圖案) – marcel