How to Resolve Vitest `EMFILE: too many open files` Errors on a High Thread Count Machine

If you’re running your Vitest suite on a high thread count machine—like an 8-core or 16-core development machine—you may encounter a frustrating error that looks like this: EMFILE: too many open files This issue can be cryptic at first, especially when your system doesn’t seem anywhere near running out of resources. But the root cause might not be in your system limits—it could be in your import statements. The Unexpected Culprit: Named Imports from MUI In my case, after hours of digging, I discovered that the error was caused by using named imports from Material UI (MUI) components and icons. These named imports, when used across many test files, were triggering Vitest to open an excessive number of files behind the scenes. ...

How to create a custom React hook for locale-specific date formatting

In this post, I will show you how to create a custom React hook that provides locale-specific date formatting functions. This hook can be useful if you want to display dates and times in different languages and formats depending on the user’s preferences. What is a custom React hook? A custom React hook is a function that starts with the word use and may call other hooks. Custom hooks let you reuse stateful logic between components without duplicating code or introducing complex patterns. You can learn more about custom hooks from the official React documentation (1) or this tutorial (2). ...