0

I'm creating a react application, and I want to keep all my string constants in a single file like:

export const STR_LOGIN = "Log in"; //h1 on a login page
export const STR_USERNAME = "Username"; // Placeholder on a text input
export const STR_ERR_PASSWORD_TOO_SHORT = "Sorry, your password must be at least 8 characters"; // Error message on form 
export const STR_FN_WELCOME_TO_SERVICE = (name) => `Hi ${name}, welcome to XYZ service. We're so glad to have you here.`; // paragraph text

Note that the combination of string constants, and functions that return formatted strings.

What naming conventions are there for this kind of list of constants - considering that there are potentially hundreds of them?

The label of the string needs to make it clear where and how the string is being used.

The reason I want to put these all into a single constants file - is in the case that the content needs to be changed later - they can be changed in one place, rather than having to hunt through the file system to change each one.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.