Using runtime resolved objects as message descriptors for defineMessage/s in react-intl

Short answer, you can’t

See, react-intl resolve translations in compile time. If you define your messages using defineMessage to resolve in runtime, your app will fail to compile, an error like the below will be thrown.

Cannot read property 'name' of undefined

So never use defineMessage as below

defineMessage(attachment.message)

Instead define it like this

defineMessage({      
id: "attachment.quoteCostCalculation.label",
defaultMessage: "Cost calculation",
description: "Cost calculation label"
})

--

--

Dinanjana Gunaratne

Software engineer in the making. I blog tech and life experiences here. You’re in for a mix bag