Home > database >  Rendering string from MYSQL in div removes all white space
Rendering string from MYSQL in div removes all white space

Time:04-28

I am trying to render a string with spaces and line spaces in it.

When I render the string as a value on an input, the spaces show as expected.

<textarea
  rows={15}
  value={content}
/>

When I render the string in a div, all of the white spaces are removed.

<div dangerouslySetInnerHTML={{ __html: content }} />

How can I render a string in the div without removing the white space?

CodePudding user response:

You could apply white-space: pre-wrap; style to your div, so the white spaces will be displayed

  • Related