Firebase with React

We are done creating a React form where you can raise the ticket into Helpdesk and save to Firebase. For this, now we need to integrate and initialize the Firebase in our existing application.

Here's how it looks:

Added script tag at the bottom of our HTML:

<!--Firebase Config -->
<script src="js/firebase-config.js"></script>
<!--ReactJS Form -->
<script type="text/babel" src="js/react-form.js"></script>

Copy the existing Firebase config code from the previous chapter into firebase-config.js:

 // Initialize Firebase
var config = {
apiKey: "<PROJECT API KEY>",
authDomain: "<PROJECT AUTH DOMAIN>",
databaseURL: "<PROJECT DATABASE AUTH URL>",
projectId: "<PROJECT ID>",
storageBucket: "",
messagingSenderId: "<MESSANGING ID>"
};
firebase.initializeApp(config);
var firebaseDb = firebase.database();

Also, add Reactjs Form into react-form.js so that our code looks clean and manageable:

class AddTicketForm extends React.Component {
constructor() {
super();
this.handleSubmitEvent = this.handleSubmitEvent.bind(this);
}
handleSubmitEvent(event) {
event.preventDefault();
console.log("Email--" + this.refs.email.value.trim());
console.log("Issue Type--" +
this.refs.issueType.value.trim());
console.log("Department--" +
this.refs.department.value.trim());
console.log("Comments--" + this.refs.comment.value.trim());
},
render() {
return ();
}
};
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset