Closed gomorizsolt closed 4 years ago
Questions.
How to structure helpers
?
helpers.js
) which includes all the component-specific functions.Where should custom errors be located? Outside or inside src
?
utils: Non-UI / non-component / utility features not tightly linked to the specific project I would propose naming it
helpers
I think utils
are the correct name. From our earlier example, MediumUtils
would still themselves be non-component even though they are related to a component.
How to structure helpers?
Group them by functionality. E.g. MediumUtils
can contain one or more functions. I would propose to store them in a utils
folder though as with test
and style
or routes
files we already have many on the same level.
Where should custom errors be located? Outside or inside src?
Sounds like a separate topic not sure how this came up. But inside for sure. They can be scoped for the whole project or specific components.
Sounds like a separate topic not sure how this came up.
It's true, but realized we haven't agreed upon this.
Thanks for the answers, updated the structure. I have also renamed the *.css
files to *.style.js
as we use CSS-in-JS over regular CSS.
Done some updates in https://github.com/c-hive/guides/commit/801f3bafff3396c3383627ebea12e740c33936dd and https://github.com/c-hive/guides/commit/6ffb4046c4f56124f5296ee447600bb83ef57c44
I'm not sure we explicitly should point out a utils folder as it's more the exception. If it makes sense, use it for sure. With hooks, it is also easier to break down logic into smaller components/files. Therefore I'd consider separating "utils" a sign of the component is too big.
Closing unless there're further comments.
Some of our projects contain functions in the
utils
folder that are tightly coupled to a specific component and are no longer reusable in any way. This is a bad practice due to the intention ofutils
:We have therefore decided to extract the specific functions alongside the component they belong. I would propose naming it
helpers
but other suggestions are welcome.Reference: