bsky
bsky

Reputation: 20222

Import object contained in another object

I want to do something like this, but using import rather than require:

const MySubmodule = require('react-native').MyModule.MySubmodule;

I tried:

import { MySubmodule } from 'react-native/MyModule';
import { MySubmodule } from ('react-native').MyModule;
import { MySubmodule } from 'react-native'.MyModule;

None of these works.

So any idea how to import a module contained in another using import?

Upvotes: 2

Views: 48

Answers (1)

TimoStaudinger
TimoStaudinger

Reputation: 42450

You will have to import MyModule completely, and can then separately destructure it to get the parts you are interested in:

import {MyModule} from 'react-native';

const {MySubmodule} = MyModule;

The import statement does not support directly destructuring exports. See also this Babel issue for some more info.

Upvotes: 3

Related Questions