Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Loading js library fails

I have implemented a javascript library called Flickity and it works fine. But when I loop through a list of objects called from an api endpoint I get some errors.

The code I'm using is this:

<div class="main-carousel">

@foreach (var item in campaigns)
{
    <div class="carousel-cell"></div>
}
@code {
protected async override Task OnAfterRenderAsync(bool firstrender)
{
    if (firstrender)
    {
        await js.InvokeAsync<object>("initF");
    }
}

public List<StoreCampaignModel> campaigns { get; set; }

protected async override Task OnInitializedAsync()
{
    campaigns = await _repoCampaign.Get(EndPoints.StoreCampaignEndPoint + $"Get?orgId=11", Config.WebboxToken);
}

}

That renders the flickity object correctly but gives this error message in the console:

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at K10Forlag.UI.Shared.Flickity.BuildRenderTree(RenderTreeBuilder __builder) in C:\Users\peter\OneDrive\Websiter\Kanal10Media.UI\K10Forlag.UI\Shared\Flickity.razor:line 11 at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

So that means that campaigns is not initiiated so I'm thinking that I can either check if it's null or just initiate it as an empty list. But when I try that the javascript is not loaded correctly and the flickity object is not correctly shown.

I've included a little video to show the scenario. https://www.screencast.com/t/eksMC09oipJL

I'm not sure how to fix this but hope for help to a solution.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!