Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Where do helper and utility methods go? #1709

Closed
real-ashwin opened this issue May 9, 2016 · 3 comments
Closed

Question: Where do helper and utility methods go? #1709

real-ashwin opened this issue May 9, 2016 · 3 comments
Labels

Comments

@real-ashwin
Copy link

If I have a UserInfo component with UserInfoActions and UserInfoReducer.
The server returns user data such as

{
    fName: "first",
    lName: "last",
}

In which file do I put helper methods?
Example: getFormattedName() which returns Fname Lname in titlecase?
Should I put the method directly in the Component file or should I create a separate UserInfoHelper file for such methods?

Also, if getFormattedName() is to be shared among multiple components, where should it go?

@gaearon
Copy link
Contributor

gaearon commented May 9, 2016

Redux has no opinion on the file structure of your application.

Should I put the method directly in the Component file or should I create a separate UserInfoHelper file for such methods?

Both ways work fine.

Also, if getFormattedName() is to be shared among multiple components, where should it go?

Anywhere you like, e.g. in the same folder as components, or in a special utils folder. This makes no real difference so please do as you like best.

@real-ashwin
Copy link
Author

Thanks @gaearon for your response.

@tylerlong
Copy link

tylerlong commented Jun 25, 2017

Please check my answer: https://stackoverflow.com/a/44742666/862862

Nowadays the best practice is to put the code into utils/ folder:

  • src/
    • components/
      • ...
    • reducers/
      • ...
    • utils/
      • ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants