Categories
React Answers

How Add a
Tag in React Between Two Strings in a React Component?

Spread the love

Sometimes, we want to add a <br> tag between 2 strings i a React component.

In this article, we’ll look at how to add a <br> tag between 2 strings i a React component.

Add a <br> Tag Between Two Strings in a React Component

We can add a line break character in a string to add a line break.

Then we can use the white-space: pre-line style to make them display.

For instance, we can write:

render() {
   message = `Hello n World.`;
   return (
       <div className='new-line'>{message}</div>
   );
}

in our component.

Then we can add the following CSS:

.new-line {
  white-space: pre-line;
}

Conclusion

We can add a line break character in a string to add a line break.

Then we can use the white-space: pre-line style to make them display.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *