What does it mean that React context's Consumer wraps Provider?

as follows, it is the source code in the drawer of antd. The Consumer of DrawerContext in the code actually wraps the Provider,. Isn"t it all Provider that wraps Consumer? how do you understand it?

  here  

Nov.25,2021

eact-redux is an official solution, and Provider itself doesn't do much, just putting store in context. In fact, if you use react-redux, the best way to connect the view to the data layer is to use the connect function. In essence, Provider is to provide store for connect.


I just looked at the source code and adjusted the single test. I found that Context, is never used in Drawer and the instantiation of Context is carried out in Provider, so I understand that Provider should be wrapped in Consumer,Consumer to retrieve the instantiated Context content of Provider.

The value in the renderProvider callback parameter in

Drawer is always the default value passed in createReactContext when null, is returned by default in Consumer if the Context, passed in the context is not taken, so I don't know whether this is the bug of antd or someone else wrote it on purpose.

Menu