In this example make no sense to use a context. Context should be use only if data must be shared from components that have a distance > 2 in the hierarchy.
This approach make you use context the wrong way.
I works at startup in Japan as CTO.I'm using React and React Native mainly with Typescript.I have launched 3 web service and 4 mobile app ever using various technologies.I sometimes contribute OSS
Location
Japan
Education
Advanced Science and Engineering Electrical Engineering and Bioscience of Waseda University
Yeah of course I know what you tell.
Normally, context provider should be upper component in tree. This is for explanation.
There are some unique libraries implicitly provide limited scoped context like react-final-form its provider provide all form values via the context and hooks to access the context.
The hooks can't be used before start rendering because the scope is outer provider. So you must use consumer like above if you want to implement all logic to one component, or you'll split it to somewhat many field components with their state hooks. Form is deeply-coupled so split components per state is not so useful. Thus there are some cases to rewrite consumer to innerHooks like above means. In the other words, this is for the users of the libraries like react-admin form or react-final-form. If you use them, you'll understand what I mean. If not so, sorry I couldn't help without saying this may be not for you.
And innerHooks can write in declarative way as I added latest explanation in this article.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In this example make no sense to use a context. Context should be use only if data must be shared from components that have a distance > 2 in the hierarchy.
This approach make you use context the wrong way.
Yeah of course I know what you tell.
Normally, context provider should be upper component in tree. This is for explanation.
There are some unique libraries implicitly provide limited scoped context like react-final-form its provider provide all form values via the context and hooks to access the context.
The hooks can't be used before start rendering because the scope is outer provider. So you must use consumer like above if you want to implement all logic to one component, or you'll split it to somewhat many field components with their state hooks. Form is deeply-coupled so split components per state is not so useful. Thus there are some cases to rewrite consumer to innerHooks like above means. In the other words, this is for the users of the libraries like react-admin form or react-final-form. If you use them, you'll understand what I mean. If not so, sorry I couldn't help without saying this may be not for you.
And innerHooks can write in declarative way as I added latest explanation in this article.