addEventListner is not calling for First Time

const handleCharacterChange = (value,event) => {

    const plainText = value.replace(/</?[^>]+(>|$)/g, '');
    
    if (plainText?.length <= 250) {
        console.log(plainText,"jkldnaslkndlkas")
        setText(value)
    }else{
        console.log("aklsndakslmdlamsdlasmd  else ")
        document.getElementById("quill")?.addEventListener('keydown', (e) => handlePasteData(e));
    }

}

The Event Listener isn’t calling the first time

if user input exceeded from the max value it should prevent function