score:0

Accepted answer

it looks you call canceldrawing only when isdrawing is truthy?

const toggledrawing = react.usecallback(
    async (itemid: string | null) => {
        isdrawing && canceldrawing();
        itemid && (edititemid !== itemid) && startdrawing(itemid);
    }
);

score:1

if(isdrawing || edititemid === itemid) {
            canceldrawing();
            itemid && startdrawing(itemid);
} else {
            itemid && startdrawing(itemid);
}

Related Query

More Query from same tag