Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6581

Why does TypeScript module re-exporting behave like lazy loading?

$
0
0

I'm currently using the following versions of tools:

  • React-Native 71
  • React 18.2
  • TypeScript 4.8.3

In JavaScript, we have the mechanism of named re-export and re-exporting all the content of a module. For instance:

// foo.tsconsole.log('JS see it')export const myFunc = () => {…}
// index.tsexport * from 'foo'; // re-exporting everything//  VSexport {myFunc} from 'foo'; // re-exporting only myFunc

Afterwards, I use this function in another module:

// myComponent.ts...import {myFunc} from './index';myFunc();

I've noticed that when I perform the re-export of all the content of the module 'foo', I see the logs that I invoke in the 'foo' module when the application starts. However, when I do a named re-export, the logs don't appear until the first time I call the re-exported function.

This reminds me of lazy-loading module behavior.

Could you please explain why this is happening?


Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images