How to deal with multiple uses of React-Intl messages?

I can not find anything in the docs react-intl(I use the branch v2) regarding this kind of use, so this is the problem. Is there a recommended approach for the following use case?

Say I have 2 components, Tooltipand Select. Both require the same line in i18n format, for example:

<FormattedMessage
    id='ui.widget.cycleOffsetSelector.timeCycle.label'
    defaultMessage="This {cycle}"
    values={{cycle: props.cycle}}
/>

How to use the same message in another component? Just using this:

<FormattedMessage
    id='ui.widget.cycleOffsetSelector.timeCycle.label'
    values={{cycle: props.cycle}}
/>

doesn't work (shouldn't :)). So what is the right way to do this? Should I store these generic messages somewhere on a global scale in my application? Because it can become cumbersome by maintaining a list of "general" internal messages, separate from the code, that which claims react-intl.

+4
1

-intl v2 , . , , . . , (HOC) .

HOC , :


defineMessages() , , , , .


.

ui.widget.cycleOffsetSelector.timeCycle.select.label ui.widget.cycleOffsetSelector.timeCycle.tooltip.label

+5

Source: https://habr.com/ru/post/1624962/


All Articles