【发布时间】:2017-09-05 05:07:49
【问题描述】:
我注意到我倾向于在解构并返回具有值的对象时执行以下结构。
const { isLoading, fieldValues, stage } = state.personalInformation
return {
isLoading,
fieldValues,
stage,
};
只有三个参数就可以了,但是当我需要传递很多参数时,它会很快变得讨厌。
不解构感觉太冗长了。
return {
isLoading: state.personalInformation.isLoading,
fieldValues: state.personalInformation.fieldValues,
stage: state.personalInformation.stage,
};
有没有办法避免这种模式?
【问题讨论】:
-
为什么不能直接返回
state.personalInformation -
personalInformation 中有一些字段我不想返回
-
@Ionthas 为什么不让调用者关心使用哪些字段?
-
“这很好,只有三个参数,但是当我需要传递很多参数时” 什么是替代方案,一个对象有多个不同的属性,但不是对象的所有属性,都被引用了吗?