Skip to content

Is there a way to output mutli-line text with line breaks? #401

@grahaml

Description

@grahaml

Hi,

Thanks to the team for all your hard work on this fantastic library!

I have a problem that I haven't been able to figure out... and forgive me if I've missed this somewhere throughout the docs or in other issues.

Is it possible to output multi-line text with line breaks? Here's a simple example of what I'd like to do:

const messages = defineMessages({
  privacyPolicyBlock: {
    id: 'common.privacyPolicyBlock',
    description: 'The privacy policy in its entirety',
    defaultMessage: `
    This is the privacy policy.

    It needs to have many paragraphs separated by newlines.

    Is this possible?
    `,
  },
});

const MyComponent = () => (
  <div>
    <FormattedMessage {...messages.privacyPolicy} />
  </div>
);

export default MyComponent;

// Output looks like
// "This is the privacy policy. It needs to have many paragraphs separated by newlines. Is this possible?"

Is there a way to get newlines with a FormattedMessage? If not, do you think there's a way that the support could be baked in? Would that interest you? I could try to submit a PR if yes.

Thanks for listening!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions