1

I have one file with RN Component PageRegistration:

const { registerUser } = require('../../db/db');

export default class PageRegistration extends Component {
constructor(props) {
    super(props);
    this.state = {
        ...
    }
}
regUser = () => {
    ...
    registerUser(user);
}

render() {
    return(
        <View style = {pageRegistrationStyle.container}>

            ...

                <TouchableOpacity onPress = {this.regUser}
                    style = {pageRegistrationStyle.registrButton}>
                    <Text style = {pageRegistrationStyle.registrButtonText}>
                        ADD USER
                    </Text>
                </TouchableOpacity>

        </View>
    )
}
}

and one more file db:

const firebase = require("firebase");

const config = {
  ...
};

firebase.initializeApp(config);

const db = firebase.database();

const registerUser = (user) => {
  db.ref('userData').set({
    ...
  });
};

export default registerUser;

For some reason when I import function registerUser() from db file to the file PageRegistration I get an error "Objects are not valid as a React child (found: object with keys ($$typeof, type, key, ref ...). If you mean to render a collection of children, use an array instead."

What's wrong? What did I missed? Can someone, please, help me?

Edition:

It seems like the issue is related to the content of db file. In particular - first row with import of firebase

Ivan Burzakovskyi
  • 693
  • 1
  • 8
  • 25
  • Not sure if this is your problem, but `const { registerUser }` should be `const registerUser` because it's a default export. – jmargolisvt Nov 27 '18 at 20:23
  • Unfortunately it didn't help – Ivan Burzakovskyi Nov 27 '18 at 20:25
  • The wrong import isn't causing this; errors usually have line numbers, which line is it pointing at? The code you have works (if I change it to web react: https://codesandbox.io/s/qlmm0rrzqj) Also, this seems related: https://stackoverflow.com/questions/50555275/react-native-objects-are-not-valid-as-a-react-child-found-object-with-keys –  Nov 27 '18 at 20:36
  • It points to the several lines in .../node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js: 9616:6 (10679:31, 11114:6, 11612:6 and others). The first suberror calls "throwOnInvalidObjectType" – Ivan Burzakovskyi Nov 27 '18 at 20:41
  • show *all* your markup. The problem is most likely that you have some JSX expression returning something that isn't a React element. Without seeing all the markup in the file where the error is thrown it's going to be hard to debug – Robbie Milejczak Nov 27 '18 at 20:47
  • After debugging I found that the issue is related to the row "const firebase = require("firebase");". But why? And how to fix it? – Ivan Burzakovskyi Nov 27 '18 at 21:16

2 Answers2

0

There are two ways to export functions, default and normal.

In db you are exporting default, so you should not use brackets when you import the function. This should work.

const registerUser = require('../../db/db');

Treebeard
  • 64
  • 1
  • 7
0

The issue was solved after downgrading firebase to 4.9.1 version

Ivan Burzakovskyi
  • 693
  • 1
  • 8
  • 25