React: Trigger onChange if input value is changing by state? override the value of input box

 


input = document.getElementById(id-of-the-input-box);


lastValue = input.value;


console.log(lastValue)
input.value = new-value-here;


event = new Event(“change”, {
bubbles: true
});


tracker = input._valueTracker;


if (tracker) {


tracker.setValue(lastValue);


}


input.dispatchEvent(event);


Leave a Comment

Your email address will not be published. Required fields are marked *