drcmda / react-contextual

🚀 react-contextual is a small (less than 1KB) helper around React 16s new context api
MIT License
642 stars 23 forks source link

subscribe HoC is broken when ProviderContext is not given #17

Closed songguoqiang closed 6 years ago

songguoqiang commented 6 years ago

Hi, I found an issue in the latest release.

While I am using the subscribe HoC in the following way

subscribe(mapContextToProps)(AnyComponent)

I found the mapContextToProps function is called twice. The first time when it's called, there is no context information passed in, and in the second call, the context information from ProviderContext is provided.

As a walk around, I have to use

subscribe(ProviderContext, mapContextToProps)(AnyComponent)

Which works for now.

drcmda commented 6 years ago

@songguoqiang good catch, this was a large logical flaw internally. Could you try again with 4.0.2? Just watch out, it needs React 16.3.1 now.

songguoqiang commented 6 years ago

@drcmda I tried with 4.0.2 release and the program is gone.