Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

513
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!