Stateful Components
Describes what a stateful Component is and how to create it
public class BusyPageState
{
public bool IsBusy { get; set; }
}
public class BusyPageComponent : Component<BusyPageState>
{
protected override void OnMounted()
{
//Here is not advisable to call SetState() as the component is still not rendered yet
State.IsBusy = true;
//just for a test run a background task
Task.Run(async () =>
{
//Simulate lengthy work
await Task.Delay(3000);
//finally reset state IsBusy property
SetState(_ => _.IsBusy = false);
});
base.OnMounted();
}
public override VisualNode Render()
=> ContentPage(
ActivityIndicator()
.Center()
.IsRunning(State.IsBusy)
);
}

Updating the component State



Updating the state "without" triggering a refresh
Last updated