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

141
Visualizações
if a useState holds a string, does setting it to an identical string trigger downstream dependencies?
const [stuff, set_stuff] = useState("a")


...

set_stuff("a")

when set_stuff("a") is run, will it trigger downstream?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As per the documentation (of which another part was cited in the comments),

If you update a State Hook to the same value as the current state, React will bail out without rendering the children or firing effects. (React uses the Object.is comparison algorithm.)

which means that no, setting the state to the same value it had should not trigger a re-render or re-computing any dependents; set_stuff(stuff) should generally be a no-op. Of course, a re-render may trigger at the same time for unrelated reasons.

Also, remember that Object.is compares objects by identity (so-called ‘shallow’ equality), which means updating the state to an object with the same properties as the old one will not be considered identical and will trigger a re-render, even if the programmer considers the new state equivalent.

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