0

i want to refactor the below ifelse code

below is my code,

const toggle = React.useCallback(
    async (itemId: string) => {
        if (isDrawing && editItemId === itemId) {
            cancelDrawing();
        } else if (isDrawing) {
            cancel();
            itemId && startDrawing(itemId);
        } else {
            itemId && startDrawing(itemId);
        }
    }
);

could someone help me with this. thanks.

2 Answers 2

1
if(isDrawing || editItemId === itemID) {
            cancelDrawing();
            itemId && startDrawing(itemId);
} else {
            itemId && startDrawing(itemId);
}
Sign up to request clarification or add additional context in comments.

Comments

0

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);
    }
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.