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.

`render` function called but row is not updated until user scrolls

See original GitHub issue

Hello (again)

Ticket title is long but tells already a lot. I have interactive elements inside the list rows, like a favorite icon. When clicking/tapping this icon, the props are properly updated, the render function is called, but the row isn’t updated until the list is scrolled.

You can see it in action here: http://ph-dev.mobile-spot.com

Is this something you are familiar with? or am I doing something wrong?

Initially there was :

  • props:
    • favorites
    • items
  1. In the row renderer function I would check if item.id is in favorites. In this case when the user interacts with a favorite icon, only the prop favorites is updated, render function is called.

  2. Then I tried something else. I removed the prop favorites, and upstream in the reducer I set the isFavorite property directly on each item. In this case when the user interacts with a favorite icon, the prop items is updated (without mutation), and render function is called. The result is the same. It is only when the list is scrolled that the row is updated.

Do you have any tip/advice?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
bvaughncommented, Jan 17, 2019

I don’t really have the time to dig through live production app source code for GitHub questions 😄 I usually ask for smaller repro cases. In this case, since you provided source for list/item, I’ll take a stab at it.

When clicking/tapping this icon, the props are properly updated, the render function is called, but the row isn’t updated until the list is scrolled.

Which “render function” is called? I assume you mean the one inside of your _List component (which renders the react-window FixedSizeList).

FixedSizeList is a pure component, meaning that it doesn’t re-render unless its props change. In the case of a click, you aren’t passing any new props to the list, so it doesn’t know that it needs to re-render.

The solution I would typically recommended for this– (to fix the re-rendering and to remove the extra rowRenderer wrapper component you have around every item)– is to use the itemData prop mentioned in the docs to pass data directly to your item renderers. In your case, it looks like it might be expensive to pre-compute that data though, so you’ll have to decide for yourself whether it’s worth doing.

I don’t even see where/what is updating isFavorite from the two components you linked to, so I’m not sure how you would implement this exactly either– but the general idea would be that you need to pass an itemData value to FixedSizeList that changes when favorite changes, so it knows to r-render 😄

Hope this helps and good luck!

2reactions
bvaughncommented, Jan 17, 2019

😄 It’s fine. This was a super common question for react-virtualized, so much so that I added it to the README https://github.com/bvaughn/react-virtualized#pure-components

Maybe I should do the same here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-virtualized list item does not re-render with changed ...
MyItem is connected to a redux store and can be interacted with. However it's not reflecting any of the changes on the screen...
Read more >
Update on Async Rendering – React Blog
Sometimes people use componentWillUpdate out of a misplaced fear that by the time componentDidUpdate fires, it is “too late” to update the state ......
Read more >
Rendering large lists in React: 5 methods with examples
Explore five methods for easily rendering large lists in React, including pagination, infinite scroll, and several libraries.
Read more >
List Virtualization - Patterns.dev
The rows rendered are only a small subset of the full list with what is visible ... If you use React and need...
Read more >
Docs • Svelte
This and more details can also be found in the tutorial. <script> let arr = [0, 1]; function handleClick () { // this...
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