This component in nextjs is designed to write data to a firestore database after the user clicks a button. Unfortunately, Firebase seems to be having trouble writing the data, even though the alert message following the supposed data dump is successful. I have checked my process.env file to rule out any potential issues there.
Here's the code snippet for writing to the cloud firestore:
import firebase from 'firebase/app'
import 'firebase/firestore'
const WriteToCloudFirestore = () => {
const sendData = () => {
try {
//send data
firebase
.firestore()
.collection('myCollection')
.doc('my_document')
.set({
string_data: 'string',
more_data: 123
})
.then(alert('data sent to firestore'))
}
catch(e) {
console.log(e)
alert(e)
}
}
return (
<>
<button onClick={sendData}>send data to cloud firestore</button>
</>
)
}
export default WriteToCloudFirestore
If you need additional files, let me know. Firebase initialization has been confirmed on my app. After browsing through similar questions on this forum, I came across an issue related to null data return, but I believe that's not relevant here as I am adding data to my Firestore set method.