Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

reactjs - React Native can not write data to firestore

I have tried to write data to firestore from React Native App but it does not store in firestore. after, two minutes its throws a Warring message like "@firebase/firestore: Firestore (8.2.1): Connection WebChannel transport errored:" I don't know what should I do next. sometimes it stores correctly after 5 minutes. Please anyone can help me out?

App.js

import React, {Component} from 'react'; 
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
  TouchableHighlight, 
} from 'react-native';

import {
  Header,
  LearnMoreLinks,
  Colors,
  DebugInstructions,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

import firebase from 'firebase';
import firestore from 'firestore';


const firebaseConfig = {
  apiKey: "***********************",
  authDomain: "test1-c9930.firebaseapp.com",
  projectId: "test1-c9930",
  storageBucket: "test1-c9930.appspot.com",
  messagingSenderId: "589565665201",
  appId: "1:589565665201:web:d371e3971f45323e6d2790",
  measurementId: "G-Q8XY5NFZBY"
};

const firebaseApp = firebase.initializeApp(firebaseConfig);
const itemRef2 = firebaseApp.firestore().collection('/Users');

type Props = {}; 
export default class App extends Component <Props> {
  AddUser1(){
    console.log("Hello world");
  itemRef2
    .add({
    name: 'Ada Lovelace',
    age: 30,
  })
  .then(() => {
    console.log('User added!');
  });
  }


  render(){
    return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic"
          style={styles.scrollView}>
          
          <View style={styles.btn}>
            <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.AddUser1()}>
              <Text style={styles.loginText}>ADD</Text>
            </TouchableHighlight>
          </View>

        </ScrollView>
      </SafeAreaView>
    </>
    );
  }
}

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: Colors.lighter,
  },
  buttonContainer: {
    height:45,
    
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    marginBottom:20,
    width:250,
    borderRadius:30,
  },
  loginButton: {
    
    backgroundColor: "#00b5ec",
  },
  btn:{
    paddingTop: 80,
    paddingLeft: 30,
  }

});

Error

 WARN     [2021-01-07T10:26:30.319Z]  @firebase/firestore: Firestore (8.2.1): Connection WebChannel transport errored: {"a": {"C": 
null, "K": [Circular], "a": {"A": 0, "B": [U], "C": true, "F": 45000, "G": false, "I": true, "J": -1, "K": "fkei2znAemdEFPLNZb4Qyw", "Ka": 5000, "Ma": false, "Na": false, "Oa": false, "P": 0, "Pa": 2, "Qa": undefined, "R": [Object], "S": 0, "T": 9648, "Ta": 1, "U": true, "Ua": 10000, "V": 4, "X": false, "Y": [Object], "a": null, "b": [zd], "c": [bc], "f": [Z], "fa": false, "g": [Array], "ga": undefined, "h": null, "ha": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel", "i": null, "ia": "", "j": null, "ja": 8, "l": null, "m": null, 
"ma": 12, "na": [U], "o": 3, "oa": 600000, "pa": "OJAkHeErpL4AySc4V-WL0cDUNRYRR5EJ", "qa": -1, "ra": [Ed], "s": null, "u": 0, "v": "gsessionid"}, "b": {"database": "projects/test1-c9930/databases/(default)"}, "c": {"a": [Object], "b": 4, "src": [Circular]}, "f": {"a": [Circular]}, "i": undefined, "j": false, "l": true, "m": true, "o": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel"}, "defaultPrevented": false, "status": 1, "target": {"C": null, "K": [Circular], "a": {"A": 0, "B": [U], "C": true, "F": 45000, "G": false, "I": true, 
"J": -1, "K": "fkei2znAemdEFPLNZb4Qyw", "Ka": 5000, "Ma": false, "Na": false, "Oa": false, "P": 0, "Pa": 2, "Qa": undefined, "R": [Object], "S": 0, "T": 9648, "Ta": 1, "U": true, "Ua": 10000, "V": 4, "X": false, "Y": [Object], "a": null, "b": 
[zd], "c": [bc], "f": [Z], "fa": false, "g": [Array], "ga": undefined, "h": null, "ha": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel", "i": null, "ia": "", "j": null, "ja": 8, "l": null, "m": null, "ma": 12, "na": [U], "o": 3, "oa": 600000, "pa": "OJAkHeErpL4AySc4V-WL0cDUNRYRR5EJ", "qa": -1, "ra": [Ed], "s": null, "u": 0, "v": "gsessionid"}, "b": {"database": "projects/test1-c9930/databases/(default)"}, "c": {"a": [Object], "b": 4, "src": [Circular]}, "f": {"a": [Circular]}, "i": undefined, "j": false, "l": true, "m": true, "o": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel"}, "type": "c"}

Expected

Just want to write data to firestore


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...