im trying to search how to define a dictionary of labels values for use in all the pages of my React app, i dont know which is the correct way or the best practice for that.
Im thinking something like to define a json with key-values:
const MyDictionaryEN:{
NameHomePage: "Home page",
LabelName: "Name"
}
export default MyDictionaryEN;
And in each component only import the json file and reference the value:
import MyDictionaryEN from "./MyDictionaryEN.json"
function MyPage() {
return (
<div>{MyDictionaryEN.NameHomePage}</div>
)
}
is this correct or exist a better way?
Other way to using of global variables (or object) is add your variable in window object! for example :
then I am able to access it in every component: