I am optimizing a react/redux app and I wondered if there is the best practice to store and render hardcoded strings in such an app? Some of my components are using the same text and if there is a text change I will have to search all for all text occurrences. Would be better to have central location. I mean some static contents that y you do not want to put into state.
I would store all texts in a json object but I assume there must be a better way.
could anyone share his/her experience? any helpful tools or packages?
thank a lot for your answers!
Nothing special here really regarding react or redux, you could just create a constants file...
export const VAR_NAME = "this is some text";
export const ANOTHER_VAR = "something else";
then when you want to use, simply:
import { ANOTHER_VAR } from 'path/to/constants/file';
thank you for comments. In case, someone looks for nice solution this is - https://github.com/yahoo/react-intl
Requires some setup though but does what I wanted through making first steps towards internalization of the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With