Function CollectionRefernce.doc() requires its first argument to be of type string

Hey All

I’m working on React-native and Firestore. To add the data in the firestore the following is the code

componentWillMount() {

      AsyncStorage.getItem("logid").then((value) => {
            this.setState({"logid":JSON.parse(value) });

          insta: 0

I’m storing the logid in AsyncStorage and getting it into another screen in componentWillMount(). The above code for firestore is working fine on click events only but for react-native life cycle components its not working and the following error occurs:

Can anyone please help me out?

Thank you in advance

Hey @kaynanguarany,

this.state.logid is undefined because your firebase function is running before your logid is fetched from AsyncStorage. You need to use an async function and use await so that the firebase function doesn’t execute until after AsyncStorage fetches the value.



thnq @adamjnav

it worked…

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.