I've got a React project where I keep all components available through a single file, so instead of doing
import Foo from "./Foo.js"
import Bar from "./Bar.js"
I've got a components.js
-file with
export Foo from "./Foo.js"
export Bar from "./Bar.js"
so I can do
import { Foo, Bar } from "./components.js"
My problem is that Foo
, Bar
, and anything else I import this way is undefined
for the first "event queue", that is, if I have this file
import { Foo, Bar } from "./components.js"
console.log("FOO1", !!Foo, !!Bar)
window.setTimeout(() => {
console.log("FOO2", !!Foo, !!Bar)
}, 0)
it will output
FOO1 false false
FOO2 true true
This hasn't caused any trouble for with plain React components (functions nor classes), but when I try to use Redux's connect
-function to create a container component, it complains about the input being undefined
. I guess this is because when I declare React components, the references aren't, well, referenced directly, but when I call the connect
-function, it immediately tries to access the component and sees that it's undefined
. This is just my uneducated hypothesis though.
Why does this happen and how can I prevent it?
I thought it might've been a problem with the Stage 1 transform-export-extensions plugin, but I've used different syntax - e.g. export const Foo = require("./Foo").default
- in components.js
and the problem persists.