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

242
Visualizações
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 Respostas
Responde à pergunta

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 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