0

Consider the following example:

import ThingA from './ThingA';
import ThingB from './ThingB';
// ... import more things

const things = {
  ThingA,
  ThingB,
  // ... add more things to object
};

This code works fine, but each item being imported needs to be specified twice (once to import, once to add it to the object). Is there a way to remove this duplication?

I've taken a look at the import docs, but the syntax doesn't seem to support anything for this use case.

rouan
  • 3,579
  • 4
  • 21
  • 33

1 Answers1

1

Unfortunately it is not possible to import directly into an object property or to use the import in different expressions than standard one:

import <ImportClause> from <ModuleSpecifier>

Check here the exact import specification.

Dmitri Pavlutin
  • 16,530
  • 7
  • 35
  • 38