It's not clear to me why (in the pattern presented) the decorators don't return a subclass (which would preserve the dynamic and static properties and methods, etc). Instead you get hacks like `hoist-non-react-statics` to copy them over manually.
For context, the article advocates the following:
import GlobalClass from 'global-class'
const decorator = SuperClass =>
class extends GlobalClass {
render() {
return <SuperClass {...etc}></SuperClass>
}
}
This can be rewritten to remove the fixed dependency on `GlobalClass`, while preserving the underlying type: const decorator = SuperClass =>
class extends SuperClass {
render() {
// const SuperClass = super.constructor // if you want to be less explicit...
return <SuperClass {...etc}></SuperClass>
}
}
The only requirement is to maintain the contract outlined by the `SuperClass`, but that's what `super` is for. (By that I mean e.g. that `componentDidMount` should't be overwritten without also calling super.componentDidMount() before/after).Returning a different kind class entirely limits the utility of the pattern in general (IMO), and you lose the nice function-composition-like behaviour provided by `super.method`.