Skip to content

Commit c82d9be

Browse files
committed
Merge branch 'master' of github.com:fullstackreact/react-native-firestack
* 'master' of github.com:fullstackreact/react-native-firestack: Add the ranking best practice strategy
2 parents c83ccfb + a33cdb5 commit c82d9be

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: README.md

+36
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,42 @@ And we also export the filetype constants as well:
640640

641641
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.
642642

643+
Ranking strategy
644+
645+
Add a new record with timestamp using this solution:
646+
647+
firebaseApp.database.ref('posts').push().then((res) => {
648+
let newPostKey = res.key;
649+
firebaseApp.ServerValue.then(map => {
650+
const postData = {
651+
name: name,
652+
timestamp: map.TIMESTAMP,
653+
text: this.state.postText,
654+
title: this.state.postTitle,
655+
puid: newPostKey
656+
}
657+
let updates = {}
658+
updates['/posts/' + newPostKey] = postData
659+
firebaseApp.database.ref().update(updates).then(() => {
660+
this.setState({
661+
postStatus: 'Posted! Thank You.',
662+
postText: '',
663+
});
664+
}).catch(() => {
665+
this.setState({ postStatus: 'Something went wrong!!!' });
666+
})
667+
})
668+
})
669+
670+
Then retrieve the feed using this:
671+
672+
firebaseApp.database.ref('posts').orderByChild('timestamp').limitToLast(30).once('value')
673+
.then((snapshot) => {
674+
this.props.savePosts(snapshot.val())
675+
const val = snapshot.val();
676+
console.log(val);
677+
})
678+
643679
#### DatabaseRef
644680

645681
Firestack attempts to provide the same API as the JS Firebase library for both Android and iOS platforms. [Check out the firebase guide](https://firebase.google.com/docs/database/web/read-and-write) for more information on how to use the JS library.

0 commit comments

Comments
 (0)