Skip to content

Commit 1726053

Browse files
authored
Blazor render fragment support remark (#24509)
1 parent 8485eb5 commit 1726053

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

aspnetcore/blazor/components/index.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ In the following example, the `RenderFragmentChild` component has a `ChildConten
439439

440440
> [!IMPORTANT]
441441
> The property receiving the <xref:Microsoft.AspNetCore.Components.RenderFragment> content must be named `ChildContent` by convention.
442+
>
443+
> [Event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported for <xref:Microsoft.AspNetCore.Components.RenderFragment>.
442444
443445
The following `RenderFragmentParent` component provides content for rendering the `RenderFragmentChild` by placing the content inside the child component's opening and closing tags.
444446

@@ -474,6 +476,18 @@ Alternatively, use a [`foreach`](/dotnet/csharp/language-reference/keywords/fore
474476
}
475477
```
476478

479+
> [!NOTE]
480+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`):
481+
>
482+
> ```razor
483+
> private RenderFragment RenderWelcomeInfo = __builder =>
484+
> {
485+
> <p>Welcome to your new app!</p>
486+
> };
487+
> ```
488+
>
489+
> For more information, see <xref:blazor/performance#define-reusable-renderfragments-in-code>.
490+
477491
For information on how a <xref:Microsoft.AspNetCore.Components.RenderFragment> can be used as a template for component UI, see the following articles:
478492
479493
* <xref:blazor/components/templated-components>
@@ -1506,6 +1520,8 @@ In the following example, the `RenderFragmentChild` component has a `ChildConten
15061520

15071521
> [!IMPORTANT]
15081522
> The property receiving the <xref:Microsoft.AspNetCore.Components.RenderFragment> content must be named `ChildContent` by convention.
1523+
>
1524+
> [Event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported for <xref:Microsoft.AspNetCore.Components.RenderFragment>.
15091525
15101526
The following `RenderFragmentParent` component provides content for rendering the `RenderFragmentChild` by placing the content inside the child component's opening and closing tags.
15111527

@@ -1541,6 +1557,18 @@ Alternatively, use a [`foreach`](/dotnet/csharp/language-reference/keywords/fore
15411557
}
15421558
```
15431559

1560+
> [!NOTE]
1561+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`):
1562+
>
1563+
> ```razor
1564+
> private RenderFragment RenderWelcomeInfo = __builder =>
1565+
> {
1566+
> <p>Welcome to your new app!</p>
1567+
> };
1568+
> ```
1569+
>
1570+
> For more information, see <xref:blazor/performance#define-reusable-renderfragments-in-code>.
1571+
15441572
For information on how a <xref:Microsoft.AspNetCore.Components.RenderFragment> can be used as a template for component UI, see the following articles:
15451573
15461574
* <xref:blazor/components/templated-components>
@@ -2439,6 +2467,8 @@ In the following example, the `RenderFragmentChild` component has a `ChildConten
24392467

24402468
> [!IMPORTANT]
24412469
> The property receiving the <xref:Microsoft.AspNetCore.Components.RenderFragment> content must be named `ChildContent` by convention.
2470+
>
2471+
> [Event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported for <xref:Microsoft.AspNetCore.Components.RenderFragment>.
24422472
24432473
The following `RenderFragmentParent` component provides content for rendering the `RenderFragmentChild` by placing the content inside the child component's opening and closing tags.
24442474

@@ -2474,6 +2504,18 @@ Alternatively, use a [`foreach`](/dotnet/csharp/language-reference/keywords/fore
24742504
}
24752505
```
24762506

2507+
> [!NOTE]
2508+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`):
2509+
>
2510+
> ```razor
2511+
> private RenderFragment RenderWelcomeInfo = __builder =>
2512+
> {
2513+
> <p>Welcome to your new app!</p>
2514+
> };
2515+
> ```
2516+
>
2517+
> For more information, see <xref:blazor/performance#define-reusable-renderfragments-in-code>.
2518+
24772519
For information on how a <xref:Microsoft.AspNetCore.Components.RenderFragment> can be used as a template for component UI, see the following articles:
24782520
24792521
* <xref:blazor/components/templated-components>

aspnetcore/blazor/performance.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ You might be factoring out child components purely as a way of reusing rendering
167167

168168
As demonstrated in the preceding example, components can emit markup from code within their `@code` blocks and outside of them. The <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate must accept a parameter called `__builder` of type <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> so that the Razor compiler can produce rendering instructions for the fragment.
169169

170+
> [!NOTE]
171+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`), and [event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported.
172+
170173
To make <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> code reusable across multiple components, declare the <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate as `public` and `static`:
171174

172175
```razor
@@ -923,6 +926,9 @@ You might be factoring out child components purely as a way of reusing rendering
923926

924927
As demonstrated in the preceding example, components can emit markup from code within their `@code` blocks and outside of them. The <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate must accept a parameter called `__builder` of type <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> so that the Razor compiler can produce rendering instructions for the fragment.
925928

929+
> [!NOTE]
930+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`), and [event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported.
931+
926932
To make <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> code reusable across multiple components, declare the <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate as `public` and `static`:
927933

928934
```razor
@@ -1663,6 +1669,9 @@ You might be factoring out child components purely as a way of reusing rendering
16631669

16641670
As demonstrated in the preceding example, components can emit markup from code within their `@code` blocks and outside of them. The <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate must accept a parameter called `__builder` of type <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> so that the Razor compiler can produce rendering instructions for the fragment.
16651671

1672+
> [!NOTE]
1673+
> Assignment to a <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate is only supported in Razor component files (`.razor`), and [event callbacks](xref:blazor/components/event-handling#eventcallback) aren't supported.
1674+
16661675
To make <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> code reusable across multiple components, declare the <xref:Microsoft.AspNetCore.Components.RenderFragment> delegate as `public` and `static`:
16671676

16681677
```razor

0 commit comments

Comments
 (0)