Home > Enterprise >  How to use i18n translations as a key for an object
How to use i18n translations as a key for an object

Time:09-16

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,
            },
        };

CodePudding user response:

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,
            },
        };
  • Related