JSFiddle - React, Tailwind, and code Playground

JavaScript

function htmlDecode(html) {
    var textarea = document.createElement("textarea");
    html= html.replace(/\r/g, String.fromCharCode(0xe000)); // Replace "\r" with reserved unicode character.
    textarea.innerHTML = html;
    var result = textarea.value;
    return result.replace(new RegExp(String.fromCharCode(0xe000), 'g'), '\r');
}

var text = htmlDecode("</textarea><img src=x onerror=alert(1)>");
document.body.innerHTML = text;