I have that doubt, in React I don't know what is meant by context, nor provider, nor consumer and of course I don't know how they relate to each other. I have looked in the official React documentation but it is not clear to me.
I have that doubt, in React I don't know what is meant by context, nor provider, nor consumer and of course I don't know how they relate to each other. I have looked in the official React documentation but it is not clear to me.
In general, it can be said that it
ReactJS Context
is a global variablex
that goes inside a componentprovider
, which can then be consumed by the componentconsumer
, from another component in any hierarchy in the component tree,App
and thus provide the state of the variable. overallx
.Also, this global variable
x
can be modified using theconsumer
on any component in the hierarchy tree, this causes the to be returnedApp
again with the current state ofx
.Demos Available
It has many use cases, when to use context and when not, how to use it etc...
I suggest to continue in the official doc