Zaid-Ajaj / Feliz

A fresh retake of the React API in Fable and a collection of high-quality components to build React applications in F#, optimized for happiness
https://zaid-ajaj.github.io/Feliz/
MIT License
544 stars 81 forks source link

Program.withReactSynchronous only accept element id as root , but I want to render react app in a shadowroot #505

Closed napretep closed 2 years ago

napretep commented 2 years ago

hi there, I want to render react app in a shadowroot, which is the element that normal document cannot find by method document.getElementById.

Unfortunately, Program.withReactSynchronous uses exactly the document.getElementById method to locate the root node, which makes it impossible to achieve my goal.

so what should I do? Is there any other way to run react app in a shadowroot?

I' m not sure where to post the question, to feliz or elmish?

napretep commented 2 years ago

oh, I solved it by adding a simple modified version in myself code file.

module app.common.modifies

[<RequireQualifiedAccess>]
module Program =
    open Elmish.React
    open Browser.Types

    module Internal  =

        open Fable.React

        open Elmish

        let withReactSynchronousUsing' lazyView2With (appEntrance:HTMLElement) (program:Elmish.Program<_,_,_,_>) =
            let setState =
                    fun model dispatch ->
                        ReactDom.render(
                            lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch,
                            appEntrance
                        )

            program
            |> Program.withSetState setState
    let withReactSynchronous' (appEntrance:HTMLElement) (program:Elmish.Program<_,_,_,_>) =
        Internal.withReactSynchronousUsing' lazyView2With appEntrance program