1

I have a dynamicly own tabs on c#,Html,css and some Js. Js just toggle style "Display" to block or none. Tabs generate with foreach.

Example:

foreach (item in TabsList){<div@RenderFragment/<div} 

Main problem: In my tabs there are some actions and data and I dont want to lose it when I Add or Delete other Tab. If I add new Tab then it will normal render without ReRender old tabs and lose data, but if I Remove from List tab which located to the left of the current selected tab then Blazor will ReRender all my Tabs and I will lose My Data. But if i remove tab to the right of the current selected tab Blazor will not ReRender All my Tabs. Is it Possible tell Blazor just remove item from TabsList and not to Rerender again my component?

0

2 Answers 2

3

This might be solvable with the @key attribute.
Without a [mre] it's not possible to be sure, you can test it:

 foreach (item in TabsList){ <div @key="item">@RenderFragment</div> } 
Sign up to request clarification or add additional context in comments.

5 Comments

Henk, with this solution, it's not "anti-performance"? i think so because you are creating like new child-component foreach item you had, i think that using shouldRender setted to false, you are re-using the same component but only rendering the first time you implement it (could be a missunderstood from my part)
I'm not totally sure - if it is about the identities (key) then your solution might end up showing the wrong tabs. But performance should be good here too.
Can you key an entire object? I would assume you would want to key to something like item.ID.
@Bennyboy1973 - Blazor knows how get the Identity it wants/needs. Passing the objkect is the common (and I assume best) practice.
@HenkHolterman tyvm that's very useful to know
1

You should set the shouldRender() method to false inside the component (this will prevent the re-render everytime you call the component, only render the first time), anyway, like a year ago, they try to solve this issue in this thread on git where there is a lot of info about the topic!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.