Titus Decali
1 min readJun 30, 2021

--

Hey Eric! I'm glad you found it useful.

The global utility functions I use are typically utilized in 3 or more components. These are things like currency formatters or functions that I use often in most projects (I used the example of copy-to-clipboard, which I don't mind keeping global even if it is only used once, because I always know where its going to be, regardless of project: `$utils.copyToClipboard()`). If you have a function that is only used in one page/component, then the best way is probably to just write it in that component's `methods` even more than separating it out and importing it.

I've been working on Blockchain-based projects recently, and in that case there are tons of generic functions that are used in nearly every component. Blockchain projects are a great use case for this, but there are plenty of projects that have their own specific utilities which are used in multiple places. For those cases I recommend using global utils.

The whole global `utils.js` file will likely be pretty small after being minimized, so loading it up front with App.js is not the worst practice as long as it doesn't get too long. Alternatively if you import them individually, remembering to import the file can be taxing on your zen coding flow.

In the end, each dev will have their own strategies to limit unnecessary imports and better file organization, which I think really comes down to balancing what you are trying to achieve with ease of use.

Thanks for reading ^^

--

--

Titus Decali
Titus Decali

Written by Titus Decali

Multi-startup founder with daily delusions of wordsmithing. Find my work on: TitusDecali.com

Responses (1)