SniberbS
Reactiflux3y ago
1 reply
Sniberb

snowberb – 11-51 Jun 14

What's preferable and why? This:
const filters: Record<GroupingTypeEnum, InstrumentTypeFilter[] | AssetClassFilter[] | undefined> = {
    ASSET_TYPE: filterTypesAssets?.data,
    INSTRUMENT_TYPE: filterTypesInstrument?.data,
  };

  const selectOptions = filters[groupingType]?.map((type) => {
    if ('instrumentTypeId' in type) {
      return {
        value: type.instrumentTypeId,
        label: type.name,
        checked: type.isIncluded,
      };
    }

    return {
      value: type.assetClassId,
      label: type.name,
      checked: type.isIncluded,
    };
  });

or this:
const options =
    groupingType === 'INSTRUMENT_TYPE'
      ? filterTypesInstrument?.data?.map(({ isIncluded, instrumentTypeId, name }) => ({
          value: instrumentTypeId,
          label: name,
          checked: isIncluded,
        }))
      : filterTypesAssets?.data?.map(({ isIncluded, assetClassId, name }) => ({
          value: assetClassId,
          label: name,
          checked: isIncluded,
        }));
Was this page helpful?