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
  • 5,339
  • 6
  • 22
  • 36

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
  • 18,122
  • 8
  • 37
  • 41