0

what is considered the best practice for string constants constants used throughout the entire application such as constants used in home screen and others, would it be considered good practice to combine them all in one file or to have multiple files- ( constants file for home screen and so on)

NQQ
  • 51
  • 1
  • 5

1 Answers1

1

There is no perfect answer to your question but just follow what makes sense to you and your project. You can also follow best practices. For example, an MVC-layered project will not have the same structure as a pure backend microservice. Still, these can have similar best practices.

To answer your question, a React Native project normally does not have a ton of constants, I don't see a real value in creating multiple files for constants. I would just have a constants.js file under /src.

src/
  - constants.js

If you still think multiple files are necessary, maybe having a /constants folder under /src will keep it organized. You can also have an index.js file.

src/
  - constants/
    - home.js
    - menu.js

Furthermore, The Twelve-Factor App suggests having constants in environment variables. Obviously, this is not very practical for variables used with UI purposes, but rather variables that are part of the configuration of your project, such as database connections, URLs, etc.

Again, the short answer is to do what you think it's best for your project (scalability and deployments) and always trying to follow common best practices.

chris
  • 2,490
  • 4
  • 32
  • 56