0

Stack: Meteor, React, Redux, React Router

Question: Where (i.e. in which file) do I instantiate Globalize? I am no expert on Globalize, but it feels like this is a somewhat global variable. So where does it go?

More generally speaking I am a bit confused as to where to put global variables in react/meteor applications. I get the whole component idea. And I write a component within its module, I import all the stuff I need and I export the component. Easy enough. However, where does the more general stuff go? Is there anything I could read up on?

Cheers

Fabian Bosler
  • 2,310
  • 2
  • 29
  • 49
  • Hey, there is a great article which I came across on the meteor chef. It refers to how to structure your app using the imports folder which was introduced after meteor 1.3. You can check [the article](https://themeteorchef.com/tutorials/understanding-the-imports-directory) out. – Ozan Jul 08 '17 at 00:19
  • Globalize offers static methods (which works like a singleton), e.g., `Globalize.formatDate(...)` and instance methods (which is not a global variable), e.g., `new Globalize("en").formatDate(...)`. I could help on the globalize side, but your questions seems a little vague to me. – Rafael Xavier Jul 08 '17 at 23:22
  • @RafaelXavier: Thx this is going in the right direction. So I guess my question is more a fundamental question. My understanding regarding ES6 modules and React is that whatever variable you define within a module, but outside a class can be accessed only from within the module (i.e. the class could access it). That's if you don't export it. Now I also know that meteor eagerly loads pretty much everything (that isn't in /imports). Now say I do **import Globalize from 'globalize'** in whatever module, does this result in a global variable, which can be used in every module without importing? – Fabian Bosler Jul 09 '17 at 09:24
  • I'm not an expert on meteor, but in ES6 in general your import statement will make `Globalize` visible in the file scope you imported it in. In every files you use `Globalize`, you should be able to import it and use the same Globalize object. – Rafael Xavier Jul 10 '17 at 17:46
  • Yea, that much I know :) ES6 is pretty clear actually. My confusion arises in combination with meteor. Thanks for your input though! – Fabian Bosler Jul 11 '17 at 10:48

0 Answers0