yahoo/fluxible

[addons-react] Following React 16.3+ new Context API ?

fsubal opened this issue ยท 7 comments

Expected behavior

React 16.3+ has now new Context API and it is deprecating legacy one like this.context = ... or static contextTypes. Maybe functions like executeAction and getStore should be provided with the new way.

Actual behavior

fluxible-addons-react does not provide those based on new context API. It still depends on the legacy one.

Information about the Issue

https://reactjs.org/docs/context.html

Steps to reproduce the behavior

None.

@fsubal We will have to take a look at the new API and see how that changes the implementation. I believe React is keeping the existing context API for sometime, but that might be just until v17 is released.

I don't believe it will be possible to upgrade to the new context api without a breaking change. We'll need some globally shared context object (react.createContext()) that both fluxible-addons-react can use for connectToStores etc, but that object must also be assessible to your app when injecting the context. If you could guarantee that everyone was already using exclusively provideContext to inject the fluxible context this would be possible, but we don't really have that guarantee.

I think that one of the large drivers of this upgrade will be hooks. useContext uses exclusively the new api, so if you want to use useContext you'll have to define your own new context object, and use the provider to inject that in addition to whatever you're doing currently to get context down to your connectToStores etc. That doesn't like a terrible interm solution in my mind.

The one thing I believe we should do immediately to help future proof fluxible-addons-react would be to actually expose the new fluxible context (along with some docs on how to inject it along side your existing context), even if its not using it internally. This would allow fluxible based libraries to upgrade to the latest context api, without introducing a doomed from the start context object that will never be used by connectToStores. It would make the future upgrade path much smoother, allowing you to opt into the double fluxible injection at your leisure, then once fluxible-addons-react was upgraded, there would be nothing to do even if it was a "breaking" change.

The PR will be tiny, so I'll go ahead and just create it, regardless of whether folks think this is a good idea.

actually, as I create the PR, it occurs to me that this might be a lot cleaner if it was just a separate yahoo npm module so it can depend specifically on 16.3. the alternative is to not export it as part of the module (so you have to import from fluxible-addons-react/context or something) and have the file assert the version of react. Something like this: https://github.com/mui-org/material-ui/blob/7d6ac7f0335252d66d97e5b812a6b7d93581b833/packages/material-ui/src/ButtonBase/ButtonBase.js#L52

in the meantime i've created fluxible-context and published it. I needed it to build the hook alternative to connectToStores, useStores as well as an internal library, but i'd be happy to move it into the yahoo org at any point.

Hi, I am one of the biggest fan of fluxible!
I have also tried to rewrite addons-react with new Context API and hooks API.
https://github.com/TasukuUno/fluxible-addons-react-16

It was not so difficult, but a new problem has occurred. handleRoute and handleHistory API of fluxible-router also depend on Legacy Context API. I think that these functions to connect component and router should be included in addons-react.

Anyway, I hope it will be supported in the near future! ๐Ÿ˜ƒ

Hi! Thanks for a great lib, been using it for years!

Any plans to go further with this issue?

FYI we have released fluxible-addons-react@1.x this week which supports React 16.3+. Sorry for the many years delay, @pablopalacios graciously migrated all the code to support the latest APIs (he gets all the praise ๐Ÿ™Œ ). Please try it out and let us know if you have any issues.

I'm going to close this issue out since the work is done, but feel free to continue to comment in here or open new tickets for related issues. Thanks!