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

235
Vistas
how do i update a navbar on an api call (specifically a google signin)

i'm having a tough time understanding the hook concept in this case:

the user signs in through google, updating the session state.

this updates a visitorType state from 'viewer' to 'buyside'...

and then my navbar is supposed to adjust. but it doesn't, unless switch from the browser to another app and then back again...

const { data: session } = useSession(); //next-auth login sessions
const [visitorType, setVisitorType] = useState('viewer')
const visitorRef = useRef(visitorType);

useEffect(()=>{
    return(
      () => {if (session) {
                           visitorRef.current='buyside';
                           setVisitorType('buyside')}
      }
  )
  },[session])

from what i understand, useRef gets the value of something between re-rerenders? and useEffect is asynchronous, so it lags behind? - so, not sure how i can update a reference..

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The function returned by useEffect fires when the components unmounts. I think what you want is:

useEffect(()=>{
  if (session) {
    visitorRef.current='buyside';
    setVisitorType('buyside')}
  }
},[session])

Regarding your question on useRef: when you set visitorRef.current. No rerender is triggered.

when you call setVisitorType, a rerender happens

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