Questions tagged [dangerouslysetinnerhtml]

64 questions
11
votes
4 answers

Javascript dynamically inserted later on: how to make it run?

I have scripts In my React app that are inserted dynamically later on. The scripts don't load. In my database there is a field called content, which contains data that includes html and javascript. There are many records and each record can include…
Nick
  • 3,496
  • 7
  • 42
  • 96
8
votes
1 answer

Next.JS - Gist's embedded in markdown rendered via dangerouslySetInnerHTML only show after full page load, not React route load

I have a series of blog posts stored in MD files, some of these contain multiple Gist embeds in the form of script tags. The MD contents are rendered to the page via dangerouslySetInnerHTML, and all is fine when the page is navigated to directly.…
Rob Earlam
  • 864
  • 1
  • 8
  • 15
4
votes
0 answers

How can I Parse a string containing JSX into JSX components

I am currently trying to parse a string that contains JSX into literal JSX,and inject it into the return of my component: import react from "react"; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles(theme => ({ …
0xdeadbeef
  • 101
  • 1
  • 5
3
votes
2 answers

How to set attribute "dangerouslySetInnerHTML" with ellipsis using antd?

I need to show comment with ellipsis. I have used antd's Paragraph Typography for it. My problem is that comment can also contain html attributes (link to tagged users) so I also need to set dangerouslySetInnerHTML in the component. How to set this…
2
votes
0 answers

How to get HTML file from firebase storage bucket and display it on React Page

I have tried a few things such as dangerouslySetInnerHTML and nothing has worked. This is my latest attempt... this.state={article:"firebaseStorageLinkToHTML"} createMarkup(){ return {__html: this.state.article}; }; return(
2
votes
1 answer

Why does NextJS give this hydration error on dev server build but not production build?

If you use create-next-app and paste this code, you get a hydration error on the client when running the next dev server. pages/index.js export async function getServerSideProps(context) { const x = Math.random(); const script = `
2
votes
2 answers

How to render CKeditor's rich text from a CMS into a Next.js app?

I'm currently using :
in order to render the rich text I get from a CKEditor input field from a Strapi CMS backend. Is there a better way to do this that doesn't use…
2
votes
1 answer

className not working on dangerouslySetInnerHTML

I've initial string like this:- My first name is @John# and last name is %Smith#. Where I'll replace:- @ with % with # with the working code…
lala
  • 1,309
  • 9
  • 21
2
votes
0 answers

react-markdown to render mix of markdown and HTML, will get warning Whitespace text nodes cannot appear as a child of
I need to render content that is a mix of markdown and regular HTML. The content is queried from server, which I can't decide whether there are whitespace inside table. for example the content raw data: # [React](https://reactjs.org/)
React is a…
wtf512
  • 4,487
  • 9
  • 33
  • 55
2
votes
0 answers

react dangerouslySetInnerHTML outputs extra newlines compared to original html code

When rendering a plain HTML code with @testing-library/react, the output HTML adds many empty lines to the input HTML(have a look at the code after toMatchInlineSnapshot ). How can I get rid of this? I just want to get the HTML as it is. import…
2
votes
1 answer

Is it wise to render a server response using dangerouslySetInnerHTML to the page without sanitization?

It is very common I think to use React's dangerouslySetInnerHTML property to place markup acquired from a server on a page, i.e. const SomeComponent = () => { const [markup, setMarkup] = useState(null) useEffect(() => { const resp = await…
fraxture
  • 5,113
  • 4
  • 43
  • 83
2
votes
2 answers

How to create a page with URL in React

The application is receiving from the server an HTML file. This data (responseToPost) can be shown on the page like this:
I was wondering if it's possible to create a new URL…
Leo Messi
  • 5,157
  • 14
  • 63
  • 125
/
data in each column of a html table
I'm trying to fill a html table with data (that I get from a http request) that are parsed in string. Like the string with data contains the
markups, I'm trying to render them with the innerHtml of Angular. But all the data are displayed…
1
vote
0 answers

getting a data as html string how can i convert it into html.I used dangerouslySetInnerHTML but the html string contains lot of /n and /r

"description": "Hello.\r\n \r\n