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

253
Visualizações
How to get a functional component to update when Redux state gets updated?

I fetch user's data (including profile picture) using Redux. Sometimes the user changes his profile picture, redux updates it well but the update only appears when I restart the app. I want it to update automatically once the user uploads a new photo. I don't know how can I do that? Is it a problem in the profile picture component or the way I fetch data using Redux.

here's how I fetch user's data:

export function fetchUser() {
  return (dispatch) => {
    firebase
      .firestore()
      .collection('users')
      .doc(firebase.auth().currentUser.uid)
      .get()
      .then((snapshot) => {
        if (snapshot.exists) {
          dispatch({ type: USER_STATE_CHANGE, currentUser: snapshot.data() });
        } else {
          console.log('does not exist');
        }
      });
  };
}

and here's the profile picture component (which I want to update every time the user updates his photo):

function DrawerProfilePicture(props) {

  const [image, setImage] = useState(null);

const { currentUser } = props;    
useEffect(() => {
      setImage(currentUser?.pp);
  }, [currentUser?.pp]);

  if (!currentUser) {
    return (
      <View>
      </View>
    );
  }

  return (

      {!image ? (
        <Image
          style={{ width: 100, height: 100 }}
          source={require('../../assets/default.png')}
        />
      ) : (
        <Avatar.Image size={100} source={{ uri: image }} />
      )}
  );
}

const mapStateToProps = (store) => ({
  currentUser: store.userState.currentUser,
});
export default connect(mapStateToProps, null)(DrawerProfilePicture);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const { currentUser } = props;    
useEffect(() => {
      setImage(currentUser.pp);
  }, [currentUser.pp]);

The problem when you use empty brackets [] its update state only once when component rendered, when you add parameters it will re-render each time this parameter updated

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