How after navigate.goBack, listen to firebase?


#1

I have two Screens: A and B

In A, I listen to firebase with on() I start listen in componentDidMount(). And if there is a live database update it is working. Before I change Screen in componentWillUnmount() I detach firebase ref listener. It is working until now.

But after I change to Screen B and then going with navigate.goBack to screen A,
I don’t get updates because, I don’t start listen again after, componentWillUnmount().

The problem is navigate.goBack don’t fire componentDidMount from Screen A!

What should I do?


#2

React should definitely call componentDidMount if your component is getting mounted again. You should try debugging with console.log calls to make sure the lifecycle methods are getting called in the way you expect before adding Firebase code.


#3

navigate to next screen don’t fire componentWillUnmount()

  componentDidMount() {
    this.getKerzenGroup('g1');
    this.getKerzenGroup('g2');
    this.getKerzenGroup('g3');
    this.getKerzenGroup('g4');
    console.log('componentDidMount');
  }

  componentWillUnmount() {
    firebase.database().ref('/groups/g1/punkte').off();
    firebase.database().ref('/groups/g2/punkte').off();
    firebase.database().ref('/groups/g3/punkte').off();
    firebase.database().ref('/groups/g4/punkte').off();
      console.log('componentWillUnmount');
  }

this.getkerzengroup … is the ref that listen to firebase


#4

so navigate to next screen is detach ref firebase listener without calling componenWillUnmount!
But how?