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

76
Vistas
React Component not re-rendering when prop changes

I have three components - layout, navigation, and room dropdown. Layout gets a property 'lobbyCode' from a database and sets it to a state, then passes it as a prop to Navigation. Navigation then passes this prop as a prop to RoomDropdown, however the room dropdown component does not re-render when the lobbyCode state is changed in layout. Navigation seems to handle the state change fine and re-renders correctly, so I'm not sure what's happening.

Layout:

const { user, isAuthenticated, isLoading } = useAuth0();
const [lobbyCode, setLobbyCode] = useState("");

return (
    <div>
       <Navigation GetUser={GetUser} GetPlayers={GetPlayers} lobbyCode={lobbyCode} user={user} 
       isAuthenticated={isAuthenticated} isLoading={isLoading} />
    </div>
  )

useEffect(() => {
    if (isAuthenticated) {
      GetUser(user.email).then(result => {
        if (result.length > 0) {
          setLobbyCode(result[0].lobby);
        }
      });
    }
  }, [user]);

Navigation:

<RoomDropdown lobbyCode={props.lobbyCode} GetUser={props.GetUser} GetPlayers={props.GetPlayers} user={props.user} />

RoomDropdown

useEffect(() => {
    console.log(props.lobbyCode);
}, [props.lobbyCode]);

The result is that the room dropdown will just print undefined and never update, even once the lobby code is loaded.

about 4 years ago · Santiago Gelvez
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