How do you perform wait/sleep in Blazor?
To perform the wait operation in Blazor, we need to use Task.Delay(Time in milliseconds) which will wait for the specified time before execution. In the sample, we have delayed the count increment by a second by using the Task.Delay() method.
How do you add dependency injection in Blazor?
Use the @inject directive to inject the service into components. @inject has two parameters (type and name). Type represents the service type and name represents the service instance name. Syntax: In the following example, we have injected the dependency IJSRuntime service, which is used for handling JavaScript interoperability to invoke a JavaScript function during a button click in Blazor. For more information, refer to this link.
Is hot reload support available in Blazor?
As of now, hot reload is not supported in Blazor, but it has been scheduled for the .NET 5 release. Please refer here for more information. However, you can use the following command in the command prompt. Also, you must include the following file types in the .csproj file for which files you want to watch. Reference Link: https://stackoverflow.com/questions/58172922/is-there-any-hot-reload-for-blazor-server-side
How do I get a specific instance of a custom Blazor component?
We can define specific instances for custom components by using @ref while defining the component in a Razor file. In this sample, we have created the component reference for the card components with specific names. Using this reference, we can access the card component properties and modify them. Here we have changed the display property using the component reference.
How do you detect whether a page is loaded in mobile or on desktop?
There is no direct way to detect whether the page is loaded on mobile or desktop in Blazor. We have to find out through the userAgent property from the JavaScript side using a JSInterop call. In order to find out, add a “script.js” file in the wwwroot folder and include the isDevice method call. You can then invoke the isDevice method to identify the correct device. Refer to the following code for further details. Refer the script file in the HTML page For more details about mobile browser detection, refer to this link.