You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to make a full-screen FlashList that is scrollable by clicking a button. I was doing this with a FlatList. However, I was facing some performance issues, so I would like to switch to a FlashList. However, the scroll button doesn't seem to work.
It will work on the first scroll, but after that no longer works.
Expected behavior
Upon clicking the scroll button it should scroll for ever item in the list.
To Reproduce
The following is a minimal example I wrote for this issue. Any help with this would be highly appreciated.
FlashList calls renderItem only when data or extraData prop changes. While your component does not change any of these props, your renderItem function will not be updated. This means it will still use old reference of scroll function. To see what i mean, try to add a console.log(currentIndex) at the beginning of scroll function. It will always print 0. Therefore, you should find another way to access latest scroll reference.
1. Option
Pass your scroll function into renderItem with extraData. In this case, FlashList will update your reference every time.
If you will prefer to use this approach then you should wrap your scroll function with useCallback. Otherwise, you will have performance issues because flashlist will update your items every time.
2. Option
You can put all your logic between setCurrentIndex so scroll function will have the latest currentIndex data. React useState setters are not reactive.
While you do not need reactiveness for the scroll, you can make your logic non reactive. You can read more about this solution here. useEffectEvent is not released yet but you can use useEventCallback which will do the job for you.
Current behavior
I am attempting to make a full-screen FlashList that is scrollable by clicking a button. I was doing this with a FlatList. However, I was facing some performance issues, so I would like to switch to a FlashList. However, the scroll button doesn't seem to work.
It will work on the first scroll, but after that no longer works.
Expected behavior
Upon clicking the scroll button it should scroll for ever item in the list.
To Reproduce
The following is a minimal example I wrote for this issue. Any help with this would be highly appreciated.
Platform:
Environment
x.y.z
The text was updated successfully, but these errors were encountered: