Skip to content
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

App crashes when trying to use scrollToEnd with empty data props passed #1485

Open
2 tasks done
YanislavRemitly opened this issue Jan 22, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@YanislavRemitly
Copy link

YanislavRemitly commented Jan 22, 2025

Current behavior

When data prop is empty array, scrollToEnd is crashing the app. The issue reproduces always.

export default function HomeScreen() {
  const { top } = useSafeAreaInsets();

  const [data] = useState<Item[]>([]);

  const ref = useRef<FlashList<Item>>(null);

  const renderItem = ({ item }: { item: Item }) => {
    return <Text>{item.title}</Text>;
  };

  return (
    <View style={[styles.container, { paddingTop: top }]}>
      <Pressable
        style={styles.scrollButton}
        onPress={() => ref.current?.scrollToEnd()}
      >
        <Text>Scroll</Text>
      </Pressable>
      <FlashList
        ref={ref}
        style={styles.list}
        renderItem={renderItem}
        data={data}
        keyExtractor={(item) => item.title}
        estimatedItemSize={20}
      />
    </View>
  );
}
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2025-01-22.at.20.41.30.mp4

Expected behavior

App should not crash.

To Reproduce

The code provided in description is enough to reproduce the issue.

Platform:

  • iOS
  • Android

Environment

1.7.1

@YanislavRemitly YanislavRemitly added the bug Something isn't working label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant