0

In react, I have the following file: constants.js, containting

export const myConstant1 = 'abc';
export const myConstant2 = 'xyz';

export const myObject = {
    myConstant1: 'This is the first constant', // myConstant1 here is NOT recognized
    myConstant2: 'This is the second constant' // myConstant2 here is NOT recognized
}

My problem is, I cannot reference myConstant1 and myConstant2 from within myObject. What am I missing?

Thanks.

Greeso
  • 7,544
  • 9
  • 51
  • 77
  • 4
    Are you trying to use those variable values as the key names in that object? If you are then wrap them in `[]`: `const obj = { [myConstant1]: 'This is...' }`. – Andy Jun 02 '23 at 19:28
  • @Andy - This worked like a charm. May I ask you to write this as an answer? So I accept it, and it is for the better good :) – Greeso Jun 02 '23 at 19:33

0 Answers0