0

I retrieve alert messages from an API and join using the \r\n method. It is joining correctly and logging correctly to the console, however it is not displaying the alerts on a new line. It instead just ignores those characters and goes on to the next part of the string.

Example:

//Thunk
if (warningResults && warningResults.length) {
          dispatch(
            upsertAppNotification(
              AppNotificationsCenter.getNotificationByKey(
                NotificationKeys.CustomerAlertWarning,
                warningResults.join('\r\n')
              ),
              0
            )
          );
        } 

I log the notification to the console and it shows like this:

Message: "Warning Message One\r\nWarning Message Two, 

But it displays on the page like this: enter image description here

Here's the code that displays the message:

{props.message && (
                <StyledTextBox data-testid={props.messageTestId} maxWidth="80%">
                  <Typography variant="paragraph">{props.message}</Typography>
                </StyledTextBox>
              )}
Sean
  • 1,368
  • 2
  • 9
  • 21
  • 1
    HTML doesn't respect `\r` you'll need to use the [line break element (`
    `)](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br) - Or use a solution in https://stackoverflow.com/questions/39325414/line-break-in-html-with-n
    – evolutionxbox Jul 19 '22 at 14:41
  • does not work either – Sean Jul 19 '22 at 14:45
  • It will work, but without you showing why your effort doesn't, we cannot help. (Do not post code in the comments) – evolutionxbox Jul 19 '22 at 14:46

1 Answers1

1

Wrap your text with pre tag

<pre>
   {message}
</pre>

or add this style: white-space: pre; or white-space: pre-line;

Oktay Yuzcan
  • 2,097
  • 1
  • 6
  • 15