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

108
Visualizações
Get notified when ref.current changes in React

Is there a way to get notified when ref.current changes in React ? Like the code below.

const ref = useRef(0);

// pseudo code
ref.addCallback((newValue)=> {
  // notified
});

ref.current = 1; // triggers the notification.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can make use of the useCallback hook like so:

const onChange = useCallback(value => {
   if(value) {
      // do whatever you want
   }
}, []);

And pass the function to the ref ref prop:

<div ref={onChange}></div>

Note that this does not trigger rerendes yet. You would need to set value to a state.

about 4 years ago · Santiago Trujillo Relatório

0

You can use a library like Observable Slim

Here is an example of how you would use it:

ObservableSlim.create(ref.current, true, function(changes) {
    console.log(JSON.stringify(changes));
});
about 4 years ago · Santiago Trujillo 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