search

Home  >  Q&A  >  body text

Append HTML string to Next.js header

<p>I am getting data from API and it gives me an object with attribute <code>head: '<title>dummy title<title>'</code></p> <p>When I call the HTML string in the head tag, it doesn't display anything. My code: </p> <pre class="brush:php;toolbar:false;"><Head>{data.head}</Head></pre> <p>I also tried: </p> <pre class="brush:php;toolbar:false;"><Head> <div dangerouslySetInnerHTML={{ __html: data.head }}></div> </Head></pre> <p>code<code><div dangerouslySetInnerHTML={{ __html: data.head }}></div></code> works for me in body but not in head, Because div cannot be called in the head. I also tried using Fragment instead of div but it doesn't work even in body. </p>
P粉031492081P粉031492081472 days ago469

reply all(1)I'll reply

  • P粉032900484

    P粉0329004842023-08-30 12:00:36

    You cannot directly convert a string or object into a label. For your use case you can split the header object to get a specific header and use that.

    reply
    0
  • Cancelreply