`render` function called but row is not updated until user scrolls
See original GitHub issueHello (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
-
In the row renderer function I would check if
item.id
is infavorites
. In this case when the user interacts with a favorite icon, only the propfavorites
is updated,render
function is called. -
Then I tried something else. I removed the prop
favorites
, and upstream in the reducer I set theisFavorite
property directly on each item. In this case when the user interacts with a favorite icon, the propitems
is updated (without mutation), andrender
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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
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.
Which “render function” is called? I assume you mean the one inside of your
_List
component (which renders the react-windowFixedSizeList
).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 theitemData
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 anitemData
value toFixedSizeList
that changes when favorite changes, so it knows to r-render 😄Hope this helps and good luck!
😄 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-componentsMaybe I should do the same here.