Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jfhector/c484884d757da4aaedf69e7ffaefa19f to your computer and use it in GitHub Desktop.
Save jfhector/c484884d757da4aaedf69e7ffaefa19f to your computer and use it in GitHub Desktop.

react-intl: When to use defineMessage and why

It's generally better to define messages inline as arguments of intl.formatMessage(...). (Because linting only works that way.)

But this pageH1Message needs to be used in two places. So we assign that message to a variable using defineMessage, then use that message in two places.

(If we had defined the same message twice inline, we'd have ended up with two identical messages in the translation file, with makes managing translation harder).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment