0

Showing the code is easier to explain what I'm looking if it is possible to do.

validations.js file

export const required = 'REQUIRED'
export const email = 'NEEDS_TO_BE_EMAIL'

translations.js file

import { required as requiredValidation, email as emailValidation } from './validations'

export const { [requiredValidation], [emailValidation] } = defineMessages({
    [requiredValidation]: {
        id: `validations.${requiredValidation}`,
        description: 'Mensagem de obrigatoriedade do campo',
       defaultMessage: '{field} é obrigatório'
    },
    [emailValidation]: {
        id: `validations.${emailValidation}`,
        description: 'Mensagem de formato de email do campo',
        defaultMessage: '{field} precisa ser do tipo e-mail'
    }
})

I would like to export consts which would be:

REQUIRED and NEEDS_TO_BE_EMAIL, is there anyway to do it?

Thanks for progress!

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Guilherme Lopes
  • 202
  • 1
  • 10

1 Answers1

1

It's not possible as far as I know. But here is what you can do. You can export a single object with dynamically generated keys though:

let obj = {};

obj[fooLabel] = fooValue;

export default obj;
Stanislau Buzunko
  • 1,630
  • 1
  • 15
  • 27