Reputation: 1
I'm working on a mobile app with react native and firebase, and I'm trying to store some information into firestore. but the function add() doesn't acctually add to the firestore, and I only get a worning when I click the buttton without any further reaction. The idea of my code is to take information from the user about an event then store it in firebase.
Here's the function I'm using to send information of the event and call [addEvent] function from the firebase API:
handleForm = () => {
var formData = {
name: this.state.eventName,
event_type: this.state.eventType,
age_group: this.state.ageGroup,
city: this.state.city,
date: this.state.date,
free: this.state.free,
adult_price: this.state.adultTicket,
kid_price: this.state.kidTicket,
location: this.state.eventLocation,
organizer: this.state.eventOrganizer,
description: this.state.eventDescription,
}
addEvent(formData);
}
which I'm calling it from a button
<Button onPress={() => this.handleForm()}>
and here is the firebase API code:
import * as fb from 'firebase';
import 'firebase/firestore';
import 'firebase/storage';
const config = {
apiKey: '**************************************',
authDomain: '**************************************',
databaseURL: '**************************************',
projectId: '**************************************',
storageBucket: '**************************************',
messagingSenderId: '**************************************',
appId: '**************************************',
measurementId: '**************************************',
};
const firebase = fb.initializeApp(config);
const db = firebase.firestore();
export function addEvent(event) {
db.collection('events')
.add(event)
.then((data) => {
console.log('Your Event successfully added!');
}).catch((error) => console.log('Error!'));
}
so I'm getting this warning, and nothing was printed in the console also the data was not added to the firestore
Warning: Possible Unhandled Promise Rejection (id: 0): ReferenceError: Can't find variable: atob
I'm using:
Upvotes: 0
Views: 1503
Reputation: 77
in your app.js file,import 'base-64' globally:
import {decode, encode} from 'base-64';
if (!global.btoa) { global.btoa = encode }
if (!global.atob) { global.atob = decode }
Upvotes: 4