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

514
Visualizações
Is there a difference between modifying properties via React.createContext() or value property?

Say you have the following code:

//App.js

//logoutHandler function defined here

function App {

const testContext = React.createContext({
  isLoggedIn: false, 
  onLogout: logoutHandler
}) 

return (
  <testContext.Provider>
  //Some code with components
  </testContext.Provider>
 )
}

Other than the fact that the values in the value property override the default values, is this any different than setting the value property in testContext like:

//App.js 

//logoutHandler function defined here

function App {
return (
  <testContext.Provider 
  value = {{
    isLoggedIn: false
    onLogout: logoutHandler 
  }}
  >
  //Some code with components 
  </testContext.Provider>
}

Thanks.

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

0

Passing value prop through the Provider is useful in many ways:

  1. Providers can be nested to override values deeper within the tree. So, you can have different values for different nodes deeper into the tree.

  2. Consumers that are descendants of a Provider will re-render whenever the value prop of the Provider changes.

You can't do this with the default value. The defaultValue stays the same and doesn't cause re-renders.

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