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?
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.