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

145
Visualizações
React ref and ref.current are returning different values

I got a problem when I can't access real value of a ref created via react useRef hook.

So I have a const st = useRef(state); and inside of it there is an object with some keys and values.

I also have a useEffect hook that updates the reference for st.current.

useEffect(() => {
  st.current = value
}, [value])

So when I am doing a console.log of the st variable it shows me an object with a current key and its value is a real time reference for the object I am putting into st.current and all the values inside are correct.

But when I am trying to console.log the st.current itself it shows me the previous state of the object. And also when I am trying to access any of the variables inside the st.current it returns the previous value :(

This is the code example. Pay your attention on selectedFolders key. It shows different values for the same object. enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
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