0

I made a function that takes an string and replace a specific substring within it:

let mark = (str: string, sub: string) : string => {
    let re = Js.Re.fromString("(" ++ sub ++ ")");
    Js.String.replaceByRe(re, "<mark>$1</mark>", str);
};

It works as expected. The problem is that, when using ReasonReact.stringToElement it escapes the string, probably for security reasons. However, I do need a way to transform my string in elements unsafely, so the <mark> tag inside it becomes a valid HTML. How can I do this?

Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43

1 Answers1

3

Use dangerouslytSetInnerHTML

It translates almost exactly syntactically to ReasonReact:

<div dangerouslySetInnerHTML={ "__html": "<mark>whatever</mark>" } />
glennsl
  • 28,186
  • 12
  • 57
  • 75