Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to convert a string to react element in javascript

<div dangerouslySetInnerHTML={{__html: value}}/>

f XSS is your primary concern, you can use DOMPurify to sanitize your HTML before inserting it in the DOM via dangerouslySetInnerHTML
3 most used sanitizer libraries:
DOMPurify
Xss.
xss-filters.
Example of valid code is
const sanitizer = dompurify.sanitize;
return <div dangerouslySetInnerHTML={{__html: sanitizer(title)}} />; 

** if those are not your solution then try this package name html-react-parser
and parse the value with qoute.
example :
import parse from 'html-react-parser'; //es

export const StringToHtml=(str)=>{
  return parse("'"+str+"'")
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: immediately invoked function expression 
Javascript :: get data from url using react 
Javascript :: react lottie 
Javascript :: node ssh 
Javascript :: forof 
Javascript :: addeventlistener javascript 
Javascript :: jest debugger node 
Javascript :: for each 
Javascript :: javascript crash course 
Javascript :: javascript remove multiple commas from string 
Javascript :: magento 2 translate js 
Javascript :: array fill 
Javascript :: how to concat nested array in javascript 
Javascript :: tostring() javascript 
Javascript :: javascript Program for Sum of the digits of a given number 
Javascript :: how to destructure props in react 
Javascript :: what is redux 
Javascript :: javascript character ascii value modify 
Javascript :: c# razor for loop javascript 
Javascript :: external script in react 
Javascript :: jquery get all classes of a div 
Javascript :: node js require all function from another file 
Javascript :: run node js 
Javascript :: ejs current year 
Javascript :: css vw not working on mobile 
Javascript :: nmapscript location 
Javascript :: react router lazy load 
Javascript :: TypeError: Object of type ndarray is not JSON serializable 
Javascript :: equality operator javascript 
Javascript :: javascript store value in array 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =