JSFiddle - React, Tailwind, and code Playground
HTML
<input name=phone />
JavaScript
$(function() {
$("input[name='phone']").keyup(function() {
var curchr = this.value.length;
var curval = $(this).val();
if (curchr == 3) {
$(this).val("(" + curval + ")" + "-");
} else if (curchr == 9) {
$(this).val(curval + "-");
}
});
});