react-native-firebase/docs/modules/transactions.md

24 lines
756 B
Markdown
Raw Normal View History

2017-03-27 10:37:07 +00:00
# Transactions
2017-04-27 11:18:12 +00:00
> Transactions are currently an experimental feature as they can not be integrated as easily as the other Firebase features. Please see the [Firebase documentation](https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction) for full implemtation details.
2017-03-27 10:37:07 +00:00
2017-04-05 08:38:28 +00:00
## Example
```javascript
const ref = firebase.database().ref('user/posts');
ref.transaction((posts) => {
return (posts || 0) + 1;
}, (error, committed, snapshot) => {
if (error) {
console.log('Something went wrong', error);
} else if (!committed) {
console.log('Aborted'); // Returning undefined will trigger this
} else {
console.log('User posts incremented by 1');
}
2017-04-27 11:18:12 +00:00
2017-04-05 08:38:28 +00:00
console.log('User posts is now: ', snapshot.val());
});
```