Stack Overflow Asked by ken setoguchi on August 18, 2020
<TextArea
defaultValue={text} // "text" is the string received from the server side
...
<TextArea
defaultValue={"hogehogennhugahugann"}
...
If you are using a native browser textarea
include a carriage return
<TextArea
defaultValue={text.replace('\n', 'rn')}
If you are using a contenteditable
component, replace n
with <br />
, and after you fetch it later on from the server, React will not immediately output your <br />
tags as HTML.
You will need to use dangerouslySetInnerHTML in order for the <br />
elements to reflect in the front-end as HTML elements.
dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from React, but you have to type out dangerouslySetInnerHTML and pass an object with a __html key, to remind yourself that it’s dangerous. For example:
This assumes
Answered by 95faf8e76605e973 on August 18, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP