Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda