-1

i just want to remove "" so insted of <H2>When Does Thor: Love And Thunder Realase &Nbsp;In Disney Plus?&Nbsp;</H2> it will be displayed as When Does Thor: Love And Thunder Realase In Disney Plus?

i have edited my question now u understand what i am looking for

enter image description here


  {posts.map((itm, k) => {
          return (
            <>
       <div key={itm._id} className="Question-one">
                <h2> {itm.Name}</h2>
                 <div>
                  {itm.htmldata}
                  </div>
              </div>
              <div className="username">
                <span className="username2">--{itm.username}</span>
              </div>
            </>
          );
        })}
      </>
vivek kn
  • 107
  • 1
  • 18
  • 45

1 Answers1

1

TLDR

For that way you can use dangerouslySetInnerHTML props in the JSX tag.

Answer

React just support innerHTML with the dangerouslySetInnerHTML. And if you just input HTML, react are going to parse it just String data type. So, you can't get what you want

<div dangerouslySetInnerHTML={{ __html: itm.htmldata }}></div>

ETC

Even you can use react-html-renderer library

Stark Jeon
  • 1,107
  • 9
  • 24
  • pls expailin this answer – vivek kn Apr 21 '22 at 08:16
  • the html code is in itm.htmldata how can i display it – vivek kn Apr 21 '22 at 08:18
  • 1
    That's going to inject the HTML into the DOM as elements. The question is asking how to **remove** the HTML entirely. – Quentin Apr 21 '22 at 08:19
  • 1
    i just i want to remove the "" so the code is displayed propery rather than with htmltags – vivek kn Apr 21 '22 at 08:20
  • Yeap I think you want to parse HTML and render with clearly just string right? – Stark Jeon Apr 21 '22 at 08:23
  • stark jeon pls help me by changing the piece of code i have provied ur explantion is not making anysence to me @Quentin pls reopen this question that answer doesnot fit my answer – vivek kn Apr 21 '22 at 08:25
  • I think Stark's answer is correct. Not sure why it has been down voted. Try something like this - `
    `
    – Anindya Dey Apr 21 '22 at 08:25
  • @vivekkn — I've reread the question twice. Either it does answer it or the question needs to be edited to clarify what you want. – Quentin Apr 21 '22 at 08:26
  • @StarkJeon i just want to remove "" so insted of `

    When Does Thor: Love And Thunder Realase &Nbsp;In Disney Plus?&Nbsp;

    ` it will be displayed as `When Does Thor: Love And Thunder Realase In Disney Plus?`
    – vivek kn Apr 21 '22 at 08:27
  • @AnindyaDey — The question says "removes all the html tags and makes it simple senteance" — this *renders* the HTML and creates elements. It doesn't remove the tags. – Quentin Apr 21 '22 at 08:27
  • 1
    And if the question is just very badly written and this is what the OP wants … then it is just a different duplicate: https://stackoverflow.com/questions/39758136/render-html-string-as-real-html-in-a-react-component that doesn't need another answer. – Quentin Apr 21 '22 at 08:29
  • I think there's lot of confusion in this question itself. The answer provided should suffice the question asked. If not, a new question with clear explanation should be opened. – Anindya Dey Apr 21 '22 at 08:30
  • @AnindyaDey ur answer is correct if u put up a answer i will give u a correct – vivek kn Apr 21 '22 at 08:35
  • @vivekkn good to know. Thanks, but unfortunately the question has been marked as duplicate and hence, no further answers can be added. But thanks anyway! – Anindya Dey Apr 21 '22 at 08:38
  • I think my answer is right? and I edit more with the example from @AnindyaDey – Stark Jeon Apr 21 '22 at 08:49