-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List Item not re-render when renderItem changes #699
Comments
If the keyExtractor stays the same all the time, items wont be rerendered due to optimization. Technically your list items are updated every three seconds. We are sure that your elements are different from the previous items, so you need to consider this and change keyExtractor function. For example: https://snack.expo.dev/@kubilaysalih/9cb1c2 |
Yeah, I guess there are a couple of ways to trigger re-render manually, like using I'm more just want to confirm if this is an expected behaviour due to the FlashList optimization logic. And as I said in the issue above, I think it would be a good idea to mention this in the docs. |
We'd really appreciate a PR updating the documentation :) |
we found a similar issue if we have a checkbox in the list, the checkbox does not re-render when we checked. |
@hotaryuzaki your answer help-me a lot, thanks! |
@hotaryuzaki thanks for your answer i leave a example here base in your answer with checkbox const [data, setData] = useState([{"checked": true, "code_postal": "760013", "id": "22943e1e-f6be-11ed-8207-9828a60f7a9e", "name": "one"}, {"checked": false, "code_postal": "760042", "id": "229444b3-f6be-11ed-8207-9828a60f7a9e", "name": "two"}])
|
I have a multi select list in which items can be marked as selected. I'm using a state to pass the data prop to the Flashlist and I'm storing the selected item in a separate state. An already selected item will get deselected if pressed again. An item gets marked as selected and deselected on first and second press as expected. My issue is that the list is failing to re-render after that in android even if I am passing the extraData prop. A previously deselected item is not getting marked as selected upon new press. It is working as expected in iOS though with the extraData prop. Am I missing something here? Any help will be appreciated.
I tried adding the extraData prop as mentioned in the documents which will trigger a re-render. But it only re-renders twice in android. After that a previously deselected item is not getting marked as selected on press. I'm using the latest version of Flashlist(1.6.3) and expo(50.0.14). |
Can you give this a try? const renderItem = useCallback(
({ item, index, extraData }) => {
return (
<List item={item} onPressMedia={onPressMedia} selectedMedia={extraData} />
);
},
[selectedMedia]
);
<FlashList
estimatedItemSize={height / 6}
data={assets}
numColumns={3}
keyExtractor={(item) => item.id}
renderItem={renderItem}
extraData={selectedMedia}
/>; cc @Hosam-hsm |
it works, but why is this even necessary |
This worked for me:
|
If you just need to change or test your list ui, you can add
|
Current behavior
List Item does not re-render when
renderItem
prop changes.Expected behavior
If this is a bug, List Item should re-render when
renderItem
prop changes,If this is expected, I think it should be mentioned in the docs since it's different from the RN
FlatList
behaviour.To Reproduce
https://snack.expo.dev/@lucissa/shopify-flashlist-renderitem
(
renderItem
gets updated when thetime
state updates, but List Item still shows the initial time)Platform:
Environment
1.4.0
The text was updated successfully, but these errors were encountered: