JSFiddle - React, Tailwind, and code Playground

HTML

<input id="txtRg" type="text" value="" onkeyup="imprimeFormatado()" />

JavaScript

function Rg(v){
    v=v.replace(/\D/g,"");
    if(v.length == 9) v=v.replace(/(\d{2})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4");
    else v=v.replace(/(\d{1})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4");
    return v;
}
function imprimeFormatado(){

        document.getElementById("txtRg").innerHTML = Rg(document.getElementById("txtRg").value);

    
}