Issue
I am working in react js . I need to dynamically use translation values as a key for an object . How can I do that. Below show the way I tried , but I am sure this is not the right way. Can anyone suggest me a better way for this purpose
const initialValues = {
i18n.t("name.drawing"): {
items: [],
startDate: null,
endDate: null,
},
i18n.t("name.dancing"): {
items: [],
startDate: null,
endDate: null,
},
};
Solution
Wrap the keys in brackets –
const initialValues = {
[i18n.t("name.drawing")]: {
items: [],
startDate: null,
endDate: null,
},
[i18n.t("name.dancing")]: {
items: [],
startDate: null,
endDate: null,
},
};
Answered By – larz
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0