0

I have an index.js file (entry point in my react app) that imports 2 named exports from another file like so:

import { funcA, funcB } from './myFuncFile

and in myFuncFile I have an if statement at the top like so:

if (process.env.NODE_ENV === "local") {
   // do some stuff
}

this might be a silly question but how is that if statement being called?

I assumed I'd have to import the whole file like:

import * as myFun from './myFuncFile

to get the if block to work? is the mere fact I'm just importing it, causing the if block to execute?

Red Baron
  • 7,181
  • 10
  • 39
  • 86

1 Answers1

0

The simple answer is yes. When the file is imported as a whole, then this line will be triggered when the exported statements are loaded into memory.

Alex Ander
  • 1,430
  • 12
  • 19