Reputation: 138
I've tried to search for an answer, but I didn't found one. Maybe I don't know the keywords.
In react, in order to give a component access to a certain value anywhere in your app, we usually use createContext
+ Provider
+ useContext
.
I've read too that we can skip the Provider
step, passing the createContext
a value.
My questions are:
Provider
step like mentioned above, we couldn't change the value of the context, right?Upvotes: 4
Views: 1086
Reputation: 4610
Don't use context if the data you want to use is statically and globally (like environment variable).
Use context if:
For example like the value of the theme
, it can be dark
or light
. The user can change the page to light
or dark
whenever he wants. In this case the context is very useful.
Upvotes: 6
Reputation: 4692
Your 2nd point won't solve the state change issue. So, even after the update, your particular variable's value will remain the same, thus, won't make any difference.
Upvotes: 0