JS是给我们用的,不是用来搞八股文的,不到20行代码搞定React恶心人的“嵌套地狱”,拿走不谢,效果:

export default new Handle(Index)
.by(observer)
.by(memo)
.get()

class Handle<T> {
private el: (props: T) => JSX.Element | null

constructor(el: (props: T) => JSX.Element | null) {
this.el = el
}

public by(fn: Function) {
this.el = fn.call(this, this.el)

return this
}

get() {
return this.el
}
}
展开
评论