JSFiddle - React, Tailwind, and code Playground

HTML

<div id="clickr">click me</div>
<div id="status"></div>

CSS

#clickr {
  background-color: red;
  color: white;
  padding 10px;
}

JavaScript

$.fn.escape = function (callback, once) {
    return this.each(function () {
        $(document).on("keydown.escape", this, function (e) {
            var keycode = ((typeof e.keyCode !='undefined' && e.keyCode) ? e.keyCode : e.which);
            if (keycode === 27) {
                callback.call(this, e);
                if (once) $(document).off("keydown.escape");
            };
        });
    });
};

$('#clickr').on('click', function() {
$('#status').html('escape active');
  $('#clickr').escape(function() {
    $('#status').html('escape inactive');
  }, true);
});