vendredi 29 octobre 2021

How to reduce cognitive complex in javascript event handler?

I have some element event handler uses if statement inside, why sonar complains this if statement causes cognitive complexity? Is there a way I can avoid this or improve this?

const handleOnBlur = () => {
    if (isEditMode) {
        setMyStuff(false);
    }
};

This is counted as code smell +2, including 1 for nesting. Why if statement causes code smell especially I don't have very complex if, else or nested if statements.

Thank you!

Aucun commentaire:

Enregistrer un commentaire