How to cancel a Firebase transaction

To cancel a Firebase transaction, return nothing or undefined.

Example:

javascript
runTransaction(ref(db, '/whatever'), value => value ? undefined : 'New')

You are rejecting the Promise by returning undefined, thus the transaction will be cancelled.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.