Skip to content

Instantly share code, notes, and snippets.

@tjkang
Created March 23, 2017 03:35
Show Gist options
  • Save tjkang/1723d4679680b4b65b1bcf2c5ab841e0 to your computer and use it in GitHub Desktop.
Save tjkang/1723d4679680b4b65b1bcf2c5ab841e0 to your computer and use it in GitHub Desktop.
Sending a push notification from the RN App
_onPress = () => {
const subjectsRef = firebase.database().ref('subjects');
const notificationReqsRef = firebase.database().ref('notificationRequests');
const subjectData = {
author: 'TJ',
title: this.state.subjectText,
};
const notificationReq = {
from_username: 'TJ',
message: `just posted new topic "${this.state.topicText}"`,
};
const newSubjectKey = subjectsRef.push().key;
const newNotificationReqKey = notificationReqsRef.push().key;
const updates = {};
updates[`/topics/${newSubjectKey}`] = subjectData;
updates[`/notificationRequests/${newNotificationReqKey}`] = notificationReq;
firebase.database().ref().update(updates);
this.setState({
subjectText: '',
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment