I have multiple cases throughout my app that look something like this:
getVariables() {
const {
allowCustomValues,
budgets,
budgetsToAdd,
budgetsToRemove,
isGlobal,
isRequired,
name,
tagTypeId,
valuesToAdd,
valuesToDelete,
} = this.props;
return {
allowCustomValues,
budgets,
budgetsToAdd,
budgetsToRemove,
isGlobal,
isRequired,
name,
tagTypeId,
valuesToAdd,
valuesToDelete,
};
}
This seems very cumbersome, but the shorter solution involves preceding every variable I want with this.props.
, which isn't really better from a maintenance standpoint.
What I'd like is something like:
getVariables() {
return this.props.{
allowCustomValues,
budgets,
budgetsToAdd,
budgetsToRemove,
isGlobal,
isRequired,
name,
tagTypeId,
valuesToAdd,
valuesToDelete,
};
}
Is there some kind of ES6 syntax that allows me to make this code a bit more DRY?
EDIT: Possibly a duplicate of ES6 destructuring within a return statement, but that one has an accepted answer that doesn't solve the problem.