erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

What's the differences between helpers and utils? #808

Open yesmeck opened 8 years ago

yesmeck commented 8 years ago

I mean the src/helpers and src/utils folder, what files should put in helpers folder, what should in utils folder?

janhoogeveen commented 8 years ago

Looks to me like /utils is a place where you can place small snippets you can use throughout the application. Small functions to build bigger things with.

/helpers is more of a place where you store code architectural snippets in my view. Things essential for bootstrapping components and developer ergonomics.

AndrewLamYW commented 5 years ago

Looks to me like /utils is a place where you can place small snippets you can use throughout the application. Small functions to build bigger things with.

/helpers is more of a place where you store code architectural snippets in my view. Things essential for bootstrapping components and developer ergonomics.

Hi @janhoogeveen, thanks for the answer. I couldn't quite grasp it, could you please explain in other form? Thank you :D

thiagovilla commented 4 years ago

I've run into this "issue" too while trying to structure a project. Here's how it fits me better:

PointerToNextPole commented 2 years ago

I just search "helper vs utils" on google and found the issue. I got the wanted answer at StackOverflow, so let me show the URL of the question at StackOverflow: What are the differences between Helper and Utility classes?

In short, the answer is:

A Utility class is understood to only have static methods and be stateless. You would not create an instance of such a class. A Helper can be a utility class or it can be stateful or require an instance be created. I would avoid this if possible.

pedronastasi commented 1 year ago

Hope it helps someone 😄

  | Helper Functions/Classes | Utility Functions/Classes -- | -- | -- Purpose | Provide support or aid to other parts of the program | Perform common or generic operations that are not tied to any specific part of the program Scope | Typically used within a specific module or part of the program | Can be used throughout the program or in multiple programs Dependencies | Often depend on other parts of the program or external libraries | Usually independent of other parts of the program Examples | Form validation functions, data formatting classes | String manipulation functions, math libraries
XinnieSol commented 1 year ago

Nice and comprehensive explanation @pedronastasi

sktsourav commented 2 weeks ago

Is it a good practice to put the constant file inside utils folder ?

Muilibilal commented 1 week ago

@sktsourav you can create a "constants" folder and keep your constants.js file inside it. Better still you can have an index.js file inside there then have a different files for different contexts and export them from index.js. This would help you keep all your constants in a centralized place whenever you decide to create constant values for different modules in your application.