Home > Software engineering >  How to display only tag <h1> in string, reactjs
How to display only tag <h1> in string, reactjs

Time:08-31

how to display only tag in variable string,

const textHtml = "<h1>What events are you looking for today?</h1> <p>Find more events you want!</p>"

output : What events are you looking for today?

and the output only display tag <h1> and the tag <p> is not showing, cause value string of textHtml is a value from api response. And i don't how to display only the tag <h1>.

can anyone help me, please? And sorry for my bad english, thankyou

CodePudding user response:

Try adding this under your code

<Markup content={textHtml} />

source: https://www.codegrepper.com/code-examples/html/display string with html tags react js

CodePudding user response:

&lt;h1&gt;What events are you looking for today?&lt;/h1&gt;

CodePudding user response:

You're storing multiple HTML elements in a string, but you'll likely want to wrap multiple elements in a <Fragment>, i.e.:

import { Fragment } from 'react'

const titleAndP = (
   <Fragment>
      <h1>What events are you looking for today?</h1>
      <p>Find more events you want!</p>
    </Fragment>
 )

CodePudding user response:

You need to wrap the code. You can do it with empty tags (typical in ReactJS)

const html = (
    <>
        <h1>title</h1>
        <p>paragraph</p>
    </>
)
  • Related