DEV Community

Discussion on: Firebase as simple database to React app

Collapse
 
rolu315 profile image
Robert

I ran into an issue with Firebase to where whenever my e.preventDefault() is right after my onSubmit handler, it will not add data to my db in prod. It works fine in development which is odd. Check out what I wrote:

onSubmit = e => {
e.preventDefault();
const { fullName, email, subject, message, error } = this.state;
let contactID = email;
db.collection("formContacts")
.doc(contactID)
.set({
fullName: fullName,
email: email,
subject: subject,
message: message
})
.then(
(window.location = "/formSuccess").this
.setstate({ ...INITIAL_STATE })
.catch(
(window.location = "/formError").this.setstate({ ...INITIAL_STATE })
)
);
};

Any thoughts?

Collapse
 
nathansebhastian profile image
Nathan Sebhastian • Edited

Hello Robert, sorry for late reply. I don't know what's wrong by simply looking at your code. There may be several causes for it. I recommend you try these suggestions:
Does the catch call ever run when you do it?
Or maybe you had the wrong credentials for production environment?

If you don't have any React error in the console, most likely something is wrong in the process of saving your data to Firebase.

Hope this helps!