Skip to content

Commit

Permalink
Update module import approach (dotnet#29545)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored and Donciavas committed Feb 7, 2024
1 parent cff1e80 commit 8e29a70
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ The following `CallDotNet1` component calls JS that directly interacts with the
</p>
@code {
protected override async Task OnInitializedAsync()
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JSHost.ImportAsync("CallDotNet1",
"../Pages/CallDotNet1.razor.js");
}
if (firstRender)
{
await JSHost.ImportAsync("CallDotNet1",
"../Pages/CallDotNet1.razor.js");
protected override void OnAfterRender(bool firstRender)
{
SetWelcomeMessage();
SetWelcomeMessage();
}
}
}
```
Expand Down Expand Up @@ -324,7 +324,10 @@ using System.Runtime.InteropServices.JavaScript;
Load the module in `Program.cs` before <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHost.RunAsync%2A?displayProperty=nameWithType> is called:

```csharp
await JSHost.ImportAsync("Interop", "../js/interop.js");
if (OperatingSystem.IsBrowser())
{
await JSHost.ImportAsync("Interop", "../js/interop.js");
}
```

`Pages/CallJavaScript2.razor`:
Expand All @@ -343,7 +346,7 @@ await JSHost.ImportAsync("Interop", "../js/interop.js");
@code {
private string? message;
protected override void OnInitializedAsync()
protected override void OnInitialized()
{
message = Interop.GetWelcomeMessage();
}
Expand All @@ -368,7 +371,10 @@ await JSHost.ImportAsync("Interop", "../js/interop.js");
@code {
protected override void OnAfterRender(bool firstRender)
{
Interop.SetWelcomeMessage();
if (firstRender)
{
Interop.SetWelcomeMessage();
}
}
}
```
Expand Down

0 comments on commit 8e29a70

Please sign in to comment.