question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeline item do not update / re-render

See original GitHub issue

Describe the bug

Timeline item do not update / re-render when model change.

Steps to reproduce (please include code)

<Timeline>
	@foreach (var item in model.Items)
	{
		<TimelineItem>
			<span>@item.Text</span>
		</TimelineItem>
	}
</Timeline>

<Button OnClick="() => visible = true">Update</Button>
<Modal Title="Title.."
		Visible="@visible"
		OnOk="@HandleOk"
		ConfirmLoading="@confirmLoading"
		OnCancel="@HandleCancel">
	<p>
		test..
	</p>
</Modal>

@code
{
	private bool visible = false;
	private bool confirmLoading = false;

	private TestComponentParam model = new()
	{
		Items = new List<TestComponentParamItem>()
		{
			new()
			{
				Text = "A",
			},
			new()
			{
				Text = "B",
			},
			new()
			{
				Text = "C",
			},
			new()
			{
				Text = "D",
			},
		},
	};

	private async Task HandleOk(MouseEventArgs e)
	{
		confirmLoading = true;

		await Task.Delay(500);

		model.Items = model.Items.Select(x => new TestComponentParamItem
		{
			Text = x.Text + "x",
		}).ToList();

		visible = false;
		confirmLoading = false;
	}

	private void HandleCancel(MouseEventArgs e)
	{
		visible = false;
	}

	public class TestComponentParam
	{
		public List<TestComponentParamItem> Items { get; set; }
	}

	public class TestComponentParamItem
	{
		public string Text { get; set; }
	}
}

Further technical details

  • AntDesign Nuget Package version: 0.7.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ElderJamescommented, Apr 17, 2021

Hi @jirisykora83 , thanks for contacting us.

Please add a @key for loop. There is the official doc about this. Use @key to control the preservation of elements and components

<Timeline>
    @foreach (var item in model.Items)
    {
        <TimelineItem @key="item.Id">
            <span>@item.Text</span>
        </TimelineItem>
    }
</Timeline>
0reactions
ElderJamescommented, Apr 20, 2021

Can you provide a better example to illustrate this please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my React component not re-rendering upon state ...
My code seems to update the state 'selectedDate' but the component does not re-render. I have tried swapping the state to a number...
Read more >
[Bug] Cluster items dont get rerender after update #741
Hello! look at this jsbin For some reason, an update call to the dataset isn't making any UI changes to items of type...
Read more >
Google Timeline Rerender problem
It works fine the first time but everytime I click on the update button the elements inside timeline don't appear.
Read more >
React component won't re-render on state change
I need to change another aspect of state (from useSelector) to actually force the react component to re-render, displaying the button. Here is...
Read more >
re-render timeline instance not working in a React app
I try to briefly describe my problem: I wrote a React application to generate a series of animations on a web page. Each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found