Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects are not valid as a React child ( found object: object with keys ($$typeof,type,key,ref,props,_owner,_store})

I am trying to use firebase on my react native app. But it gives an error. Image is here

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

like image 261
fighg Avatar asked Jun 09 '18 08:06

fighg


People also ask

How to fix objects are not valid as a react child error?

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.

Is it possible to render a list of children in react?

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.

Can I render a stack overflow object as a child?

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 {}).


1 Answers

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'

like image 160
GrokSrc Avatar answered Oct 19 '22 22:10

GrokSrc