Replies: 1 comment 3 replies
-
Hey I moved this to discussions since this is a little open ended. Mostly that there are a lot of different permutations and approaches. And most of this applies to all SPA frameworks and not specific to React or Solid. There are a few specifics though. I'm going to caution you right from the start mixing SPA frameworks in any way that isn't just 2 separate mount points on the page has lot of challenges. This is true of any SPA framework. I honestly think Web Components might be the best solution even if they carry more overhead. But first I will describe the native JavaScript solution. On the surface to embed React in Solid is pretty easy. Solid doesn't re-render so you can often just get a ref to a mount element and then just call function SolidComponent(props) {
let mount:
createEffect(() => {
// access any props or state from solid that you want to pass to the React Component and then call render
reactDom.render(/* */)
})
return <div ref={mount}></div>
} In React it is pretty similar. I actually made a codesandbox for this: https://codesandbox.io/s/solid-react-hoc-8m2yd?file=/solid-react.js. There is a real limitation here when it comes to However in practice, this is even harder. It's a bit harder because they both use their own JSX transform. You would need to make sure that your bundler knows which files to transform to Solid and which to transform to React. TypeScript likely will also complain about conflicting JSX types because React does not play nice and hijacks the global namespace. These can be somewhat alleviated by adding pragma comment to the top of the file. /* @jsxImportSource: solid-js */ However Solid still uses a custom compiler for JSX so you will need to still tell the bundler how to differentiate. One trick you could look at doing is setting the file extension like This is all a bit complicated so I think it comes down to optimizing for which library will be driving the app and then wrap the other framework sparingly. The final option which might be the best is just use Web Components for interopt. Build them separately and then just pull them together. React does not play the best with Web Components though so you might need to look into limitations there around how properties are passed. Children aren't a problem as they have to be DOM nodes so at least on Solid's side being the Web Component will work well. Solid Element package could do this easily. A web component wrapper for React might already exist to handle the challenge of slotting (that's children in Web Components). |
Beta Was this translation helpful? Give feedback.
-
I want to combine React and Solid apps using single-spa library. In the single-spa ecosystem, most of the helper libraries available expect for solid. If someone already created the library or have any approach to combine these two apps into a single page, please let me know.
Beta Was this translation helpful? Give feedback.
All reactions