Reputation: 17701
I am trying to merge the objects like as below
export const extractSourceOfData = (library, isJsonData) => {
const id = isJsonData ? library?.sourceOfData?.id : library?.sourceOfDataId;
return { codesStandardsAndGuidelines: id ? [id] : null };
};
export const extractMaterialType = (library, isJsonData) => {
const id = isJsonData ? library?.materialType.id : library?.materialTypeId;
return { constructionMaterialTypes: id ? [id] : null };
}
and in other component i am importing both above functions and merging like as below
import CODE_STANDARD_GUIDELINE, { extractSourceOfData } from '../codeStandardGuideline';
import CONSTRUCTION_MATERIAL_TYPE, { extractMaterialType } from './constructionMaterialType';
export const extractSecondaryIds = {
let secondaryIds = Object.assign{{}, ...extractSourceOfData, ...extractMaterialType };
return secondaryIds
}
but getting an error at the spread operator, could any one please help me on this, thanks in advance.
Upvotes: 1
Views: 1245
Reputation: 6346
Try:
const merged = {...extractSourceOfData(), ...extractMaterialType()};
Upvotes: 1