Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does react will convert html snippets set in dangerouslySetInnerHTML to virtual DOM?

Tags:

reactjs

I use some DOM string manipulation libraries to generate HTML string and then inject them to some React components using dangerouslySetInnerHTML in my project, does react will add them to the virtual DOM? Can I still get the performance benefits from React in this way?

like image 406
Hiber Avatar asked Dec 23 '14 03:12

Hiber


1 Answers

Yes and no. They're represented as string props, and the current html string as a whole is compared to the previous string using the equality operator.

There's no checking within the strings, or parsing the html into virtual dom. You can parse the html yourself, or modify the code generating it to output virtual dom instead.

like image 64
Brigand Avatar answered Nov 02 '22 15:11

Brigand