Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Why doesn't my component unmount even though I implemented componentWillUnmount?

I have a class component that doesn't unmount, even though I implemented componentWillUnmount on it. I tried to console.log the mounting phases; it works with the constructor and componentDidUnmount but not componentWillUnmount. Also it gives me an error: Warning: Can't perform a React state update on an unmounted component whenever I open this screen. I'm still a new learner and I don't understand the mounting concept too well.

Here's my code (it doesn't console.log "unmount"):

  constructor(props) {
    console.log('before');
    super(props);
    this.state = { doctors: '' };
    this.fetchDo = this.fetchDo.bind(this);
  }
  fetchDo() {
    firebase
      .firestore()
      .collection('Doctors')
      .get()
      .then((snapshot) => {
        let doctorsdata = snapshot.docs.map((doc) => {
          const data = doc.data();
          const id = doc.id;
          return { id, ...data };
        });

        this.setState({
          doctors: doctorsdata,
        });
      });
  }
  componentDidMount() {
    this.fetchDo();
    console.log('mount');
  }
  
  componentWillUnmount() {
    this.fetchDo();
    console.log('unmount');
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is maybe because your component is at the root of your navigation stack. It is never unmounted if it stays at the bottom of your stack. Try resetting the stack and you will see the console log.

Here is how you can reset your stack.

import { NavigationActions, StackActions } from 'react-navigation';
    const resetAction = StackActions.reset({
            index: 0,
            actions: [NavigationActions.navigate({ routeName: 'MainActivity' })],
        });
this.props.navigation.dispatch(resetAction); 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda