Add RendererInfo examples (#34116)

pull/34093/head
Luke Latham 2024-11-14 04:02:31 -05:00 committed by GitHub
parent 38acaae8cc
commit a681ae87a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 2 deletions

View File

@ -226,7 +226,30 @@ The <xref:Microsoft.AspNetCore.Components.ComponentBase.RendererInfo?displayProp
* `InteractiveAuto` for Interactive Auto.
* `InteractiveWebAssembly` for Interactive WebAssembly.
Components use these properties to render content depending on their location or interactivity status. For example, a form can be disabled during prerendering and enabled when the component becomes interactive:
Components use these properties to render content depending on their location or interactivity status. The following examples demonstrate typical use cases.
Display content until a component is interactive:
```razor
@if (!RendererInfo.IsInteractive)
{
<p>Connecting to the assistant...</p>
}
else
{
...
}
```
Disable a button until a component is interactive:
```razor
<button @onclick="Send" disabled="@(!RendererInfo.IsInteractive)">
Send
</button>
```
Disable a form during prerendering and enable the form when the component is interactive:
```razor
<EditForm Model="Movie" ...>
@ -256,7 +279,7 @@ Components use these properties to render content depending on their location or
}
```
The next example shows how to render markup to support performing a regular HTML action if the component is statically rendered:
Render markup to support performing a regular HTML action if the component is statically rendered:
```razor
@if (AssignedRenderMode is null)