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

173
Visualizações
useRef.current returns empty array while console log shows updated value

Using useRef to update a variable with an array in my Context and then pass it down to another component. Problem is, I noticed that useRef updates said variable in ComponentA.

However when I try to access said variable in ComponentB this is what I see in my console log:

useEffect useRef is it working?: 
{current: Array(0)}
current: (3) ['testingUser', 'testing', 'value']
[[Prototype]]: Object

My question is that, I see the values I updated using useRef while at the same time, when I try to access these values using availableOnlineUsers.current I just see a blank array

Here is my code in ComponentA:

...
availableOnlineUsers.current = availUsers
...

console log at this point returns:

(3) ['testingUser', 'testing', 'value']

This is my code in my Context:

...
const availableOnlineUsers = useRef([])
...

and in ComponentB this:

console.log(availableOnlineUsers.current)

returns an empty array

While this:

console.log(availableOnlineUsers)

returns:

{current: Array(0)}
current: (3) ['testingUser', 'testing', 'value']
[[Prototype]]: Object
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