JSFiddle - React, Tailwind, and code Playground

HTML

<script src="//fabricjs.com/lib/fabric.js"></script>
<canvas id="optioncanvas" width="400" height = "400" >
 </canvas>
<input type="text" id='fronttext' value="front"/>

<input type="text" id='backtext' value="back"/>

JavaScript

fabric.Object.prototype.hide = function() {
    this.setVisible(false);
  };

  fabric.Object.prototype.show = function() {
    this.setVisible(true);
  };

fabric.MyImage = fabric.util.createClass(fabric.Image, {
    type: 'Image',
    initialize: function (element, options) {
        options || (options = { });
        this.callSuper('initialize', element, options);
        this.set('imgtype', options.imgtype || 0);
    },
    
    toObject: function() {
        return fabric.util.object.extend(this.callSuper('toObject'), {
            imgtype: this.get('imgtype')
        });
    },
    
    _render: function (ctx) {
        this.callSuper('_render', ctx);
    }
});


fabric.MyImage.fromURL = function(url, callback, imgOptions) {
    fabric.util.loadImage(url, function(img) {
        callback && callback(new fabric.MyImage(img, imgOptions));
    }, null);
};

fabric.MyImage.fromObject = function(object, callback) {
    fabric.util.loadImage(object.src, function(img) {
        callback && callback(new fabric.MyImage(img, object));
    });
};
fabric.MyImage.async = true;

var canvastextobjectfront;

  var fronttext = null;
  var backtext = null;
  var frontimg = null
  var backimg = null;
  var optiontype = 0;
  var optiontypeText= "Object";


function resetCanvas(){
    
    if(canvastextobjectfront){
        canvastextobjectfront.clear();
    }
    else{
        var w = 300;
        $('#canvasBox').height(w);
        $('#optioncanvas').width(w);
        $('#optioncanvas').height(w);
        canvastextobjectfront = new fabric.Canvas('optioncanvas', {    
            selectionColor: '#ddd',
            selectionLineWidth: 1  
        });
        canvastextobjectfront.setHeight(w);
        canvastextobjectfront.setWidth(w);
    }
    
}
resetCanvas();
var imgurl = "";

fabric.MyImage.fromURL(imgurl, function(oImg) {
    frontimg = oImg;
    oImg.set({
        left: 0,
        top: 0        
    });      
    
    oImg.lockScalingX = oImg.lockScalingY  =...