4 ms·
Not quite sure what you mean. Maybe the RFC might explain the motivation a bit more? https://github.com/reactjs/rfcs/blob/master/text/0065-contexttype.md https
by danabramov 8y ago
Not quite sure what you mean. Maybe the RFC might explain the motivation a bit more?
https://github.com/reactjs/rfcs/blob/master/text/0065-contexttype.md https://github.com/reactjs/rfcs/blob/master/text/0065-contex...
The contextType API serves as a convenience for the most common case of accessing context today. While the existing render prop API is more versatile, the fact is it's awkward in some cases with classes (e.g. when you need to access it in lifecycle).
And unfortunately that means that people are stuck using the legacy context API which is even worse (it makes React bigger and slower). So we're adding a convenience to help people migrate to the new implementation with a slightly more familiar syntax.
I guess in a way it _is_ a compromise, but in our view it's better than if people just kept using the legacy context API.
Hope that makes sense.
- nicoburns 8y agocontextType API looks great. I thought when I saw the new context API that it looked neat from a code cleanliness point of view, but a bit of a pain to use. This looks much easier :)