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

[<ReactComponent>] args translation error #460

Closed JaggerJo closed 2 years ago

JaggerJo commented 2 years ago

The ReactComponent compiler plugin apparently can't deal with functions that take 2 arguments where the 2nd in optional.

The code below throws the following exception.

image

[<AutoOpen>]
module Example =

    type Person =
        { FirstName: string
          LastName: string
          Age: int }

    type UI with

        [<ReactComponent>]
        static member PersonView (person: Person, ?showAge: bool) =
            let showAge = defaultArg showAge false

            Html.div [
                Html.span person.FirstName
                Html.span person.LastName

                if showAge then
                    Html.span person.Age
            ]

        [<ReactComponent>]
        static member PersonList () =
            let people = [
                { FirstName = "Peter"
                  LastName = "Parker"
                  Age = 30 }

                { FirstName = "John"
                  LastName = "Doe"
                  Age = 40 }
            ]

            Html.div [

                for person in people do
                    UI.PersonView person
            ]

The first argument gets passed as the components props directly. It's not wrapped in a record.

image

When the optional argument is passed everything works as expected.

image

310

We're on the latest version of Feliz (1.59.0)

JaggerJo commented 2 years ago

cc @aaronmu

Zaid-Ajaj commented 2 years ago

Hi @JaggerJo thanks for filing the issue and for the details. I've pushed a fix for it as of Feliz v1.60 can you please give that. a try? thank you!

JaggerJo commented 2 years ago

Hi @JaggerJo thanks for filing the issue and for the details. I've pushed a fix for it as of Feliz v1.60 can you please give that. a try? thank you!

Works as expected now. Thanks a lot!