0

I want to develop an app that needs to use firebase database. At first For Test I am trying to develop an app that can read data from firebase database and display data on app. But I found some problem. data not showing. when I debug my code and found the problem is itemsRef is not working.

constructor(props) {
	  super(props);
	  this.state = {
	    dataSource: new ListView.DataSource({
	      rowHasChanged: (row1, row2) => row1 !== row2,
	    })
	  };
	  //this.itemsRef = firebaseApp.database().ref();
	  this.itemsRef = this.getRef().child('items');
	}

	getRef(){
		return firebaseApp.database().ref();
	}

listenForItems(itemsRef) {
  	console.log(itemsRef)
    itemsRef.on('value', (snap) => {
      // get children as an array
      var items = [];
      console.log("kjrnjhe")
      snap.forEach((child) => {
        items.push({
          title: child.val().title,
          _key: child.key
        });
      });
      this.setState({
        dataSource: this.state.dataSource.cloneWithRows(items)
      });
    });
  }
  
  componentDidMount() {
  	this.listenForItems(this.itemsRef);
  }

1 Answer 1

1

It looks everything is okay. you can create another project and try to run this code on this new project and also drop this database and create a new one and try again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.