The view function is a function returning your view elements based on the current model.
Here is an example using Fabulous for .NET MAUI:
open Fabulous.Mauiopen type Fabulous.Maui.Viewlet view model = ContentPage("Pocket Piggy Bank", Label("Hello world!"))
The view function is normal F# code that returns elements created using the View.*method calls.
View functions are particularly useful when the existence, characteristics and layout of the view depends on information in the model. Differential update is used to efficiently update the Xamarin.Forms display based on the previous and current view descriptions.
Here is a larger example:
typeModel={ Balance :decimal CurrencySymbol :string User:string option }typeMsg=| Spend ofdecimal| Add ofdecimal| Login ofstringoptionlet init()={ Balance =2m CurrencySymbol ="$" User = Some "user"}, Cmd.nonelet update msg model =match msg with| Spend x ->{ model with Balance = model.Balance - x }, Cmd.none| Add x ->{ model with Balance = model.Balance + x }, Cmd.none| Login user ->{ model with User = user }, Cmd.nonelet view model dispatch = ContentPage("Pocket Piggy Bank",(VStack(){match model.User with| None -> Button("Login", Login (Some "user"))| Some user -> Label($"Logged in as : {user}") Label($"Balance: {model.CurrencySymbol}%.2f{model.Balance}") Button("Withdraw", Spend 10.m) Button("Deposit", Add 10.m) Button("Logout", Login None)}) .padding(20.) .center())