slaveOftime / Fun.Blazor

Powered by .NET blazor!!! ❤ F#
https://slaveoftime.github.io/Fun.Blazor.Docs/
MIT License
192 stars 7 forks source link

MudSpacer' is not NodeRenderFragment? #29

Closed rabejens closed 2 years ago

rabejens commented 2 years ago

I am trying to build a table, and want to put stuff into the toolbar.

Here is what I have so far:

    MudTable'<MyTableElement>() {
        Items state.files
        Hover true
        Striped true
        ToolBarContent [
            MudText'() {
                Typo Typo.h6
                "Cool tool bar"
            }
            MudSpacer'() // << boom!
        ]
    }

Where I added the comment << boom!, the compiler complains:

The type 'MudSpacer'' is not compatible with type 'NodeRenderFragment'

How do I correctly use MudSpacer?

albertwoo commented 2 years ago

Because you are using a list to compose MudText and MudSpacer. When you call MudSpacer'() it will create a CE builder but it is not actually evaluated in fsharp so it is not NodeRenderFragment. And it is better to use below code for performance:

ToolBarContent (fragment {
            MudText'() {
                Typo Typo.h6
                "Cool tool bar"
            }
            MudSpacer'() // << boom!
})

The ToolBarContent [] is for backward compatible for v1.

albertwoo commented 2 years ago

Or if you prefer list, you can write like this:

ToolBarContent [
    MudText'() {
        Typo Typo.h6
        "Cool tool bar"
    }
    MudSpacer'.create() // << boom!
]