所以我有一些组件使用了很多函数,所以有时候为了避免让todo <Component func1={func1} func2={func2} ... />
看起来很丑,我会在组件中调用相同的函数<Component component={this} />
。所以这显然应该慢一点,但真的多少钱?这是一个糟糕的编码模式吗?我想我也可以用已使用的函数创建一个新的obj,然后将其传递给它。
getFuncs(component)
{
return { func1: ..., func2: ... }
}
在reactClass中然后调用:<Component funcs={this.getFuncs(this)} />
答案 0 :(得分:2)
const componentProps = {
func1: this.func1,
func2: this.func2
};
<Component {...componentProps} />