'What should be the best practice while refactoring React code here?
I'm trying to refactor my React frontend code, basically all the hardcoded strings are to come from CMS and for that I have made a custom hook that fetches the string my components need.
I have a constant file which previously used to refer this string file that contained all the hardcoded strings before, now since I have the hook, how do I use it to replace this string file inside my constants file?
export const SCORES_INFORMATION_BY_SEVERITY_LEVEL: Record<string, IScoreInformation> = {
[DepressionLevels.MinimalDepression]: {
score: '0 - 4',
title: 'No or minimal depression',
description: Strings.minimalDepressionDescription,
},
[DepressionLevels.MildDepression]: {
score: '5 - 9',
title: 'Mild depression',
description: Strings.mildDepressionDescription,
},
[DepressionLevels.ModerateDepression]: {
score: '10 - 14',
title: 'Moderate depression',
description: Strings.moderateDepressionDescription,
}
};
The description key here is what getting referenced from the String file as you can see.
What I thought could be a possible solution:
I decouple this part of the file and put it in the component itself that refers it as obviously I can't use hook in the consts file. The problem with that is that this constant is getting used at multiple places and I will end up repeating my code
Just make few another constants for these strings in the constant file itself and leave it be but I'm not sure if it's the right thing to do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
