dangerouslySetInnerHTML not working on <title> tag
See original GitHub issueI have a page title with coded HTML entities that I would like to render as: “New Post”
It’s delivered to React as: “New Post”
For rendering the title on the page I use this code and it works as expected:
<ArticleTitle><span dangerouslySetInnerHTML={{__html: post.title}} /></ArticleTitle>
Returns:
“New Post”
However, when I try to do the same thing for the <title>
tag I get an [object Object] returned:
<Helmet>
<title dangerouslySetInnerHTML={{__html: post.title}} />
</Helmet>
Returns:
<title dangerouslysetinnerhtml="[object Object]" data-react-helmet="dangerouslySetInnerHTML">“New Post” · RAM</title>
There’s an original title that is set per page by the server, however as you browse around I’m using React to update it on the client-side. If I remove the server-side <title>
tag, no <title>
tag is rendered at all by the front end.
Is this issue related to react-helmet or something else going on?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:11 (1 by maintainers)
Top Results From Across the Web
React dangerouslySetInnerHTML not working when using ...
It seems like this issue only occurs when you give it an escaped html. A solution implemented by @sergiotapia involves creating a helper ......
Read more >Using dangerouslySetInnerHTML in a React application
dangerouslySetInnerHTML is a property that you can use on HTML elements in a React application to programmatically set their content. Instead of ...
Read more >DangerouslySetInnerHTML in React JS Explained
dangerouslySetInnerHTML is an attribute under DOM elements in React. According to the official documentation, dangerouslySetInnerHTML is React's replacement ...
Read more >When to use dangerouslySetInnerHTML in React? - Refine Dev
Because React does not allow direct interaction with the DOM, your content ... React recognizes the HTML tags and correctly renders them.
Read more >DOM Elements - React
There are a number of attributes that work differently between React and HTML: ... style attribute as the primary means of styling elements...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is happening for me as well. Is this supported or not? If not, is there a way to get the unescaped text without ‘dangerouslySetInnerHTML’?
he
hasn’t been updated in over 4 years (Sept 2018), so I’d be wary of adopting that for security reasons