I am trying to use firebase on my react native app. But it gives an error.
my App.js code is below
import React, { Component } from 'react';
import { Text } from 'react-native';
import firebase from 'firebase';
export default class HelloWorldApp extends Component {
componentWillMount(){
firebase.initializeApp({
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
authDomain: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
databaseURL: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
projectId: 'xxxxxxxxxxxxxxxxxxxx',
storageBucket: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
messagingSenderId: 'xxxxxxxxxx'
})
}
render() {
return (
<Text>Hello world!</Text>
);
}
}
What can I do? Thanks
The React.js error "Objects are not valid as a React child" occurs when we try to directly render an object or an array in our JSX code. To solve the error, use the map () method to render arrays or access properties on the object in your JSX code. Here is an example of how the error occurs.
If you meant to render a collection of children, use an array instead - Stack Overflow Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead Bookmark this question. Show activity on this post.
If you meant to render a collection of children, use an array instead - Stack Overflow Objects are not valid as a React child (found: object with keys {}).
I had this problem today. I ran a diff on the source code between 5.0.3 and 5.0.4 and found that the exports have changed. I also found that if I change the import statement to the following that it works with the latest version (5.3.0):
import firebase from '@firebase/app'
If you're using eslint you'll probably get a complaint that it should be listed in the project dependencies, but you can ignore that.
You'll probably also want to use the actual features of firebase rather than just the core import. For example, to use the authentication module you'd add the following:
import '@firebase/auth'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With