Fork me on GitHub
#helix
<
2023-09-21
>
7tupel13:09:28

Hi, has anyone tried to use multiple react versions in the same project? Background, I'm evaluating to use helix for a project in which I would like to use react 18 but I'm required to use an external library for UI components that only supports react 16. Has anybody done something similar with success?

lilactown16:09:36

IIRC, React 17 made a bunch of changes to allow the ability to run React 17 and React 18

lilactown16:09:54

they changed they way event propagation works to happen at the root node of the app instead of listening to the document IIRC

lilactown16:09:28

it is otherwise largely no change from 16 to 17. it took us about a month to upgrade from 16 to 17 because we had a bunch of really gross hacks in our app to handle global event propagation that we didn't need anymore (and were subtly broken) after upgrading

lilactown16:09:05

that being said, I've never done it, and AFAICT you'd need to separate it into two apps - one that's React 18, and one that's React 16.

7tupel16:09:43

Yes I'm afraid the only way will be to have separate react apps and mount one inside the other. I would take the UI component library and try to make it react 18 compatible but the library is not open source and the bundle of the library I got is not exactly a charm to make it compatible with react 18

7tupel16:09:31

I guess it should be possible to build pure ui components using the library and then mount that component as r16 app inside another r18 app that provides the state handling and only passing the needed data down to the pure ui as props. Yet this will likely require to re-mount the whole r16 app when the props change I need to pass to the r16 app's root component. Not exactly a maintainable and easy to debug codebase

lilactown19:09:54

what blocks you from using React 18 with the component library?

lilactown19:09:01

it sounds like you ought to use react 16 until the library is updated for 18 tbqh

7tupel19:09:43

Unfortunately the components library breaks with react newer than 16 :/ otherwise it would not have been a thing in the first place