Invariant Violation: scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed

혜선·2022년 11월 8일
post-thumbnail

문제:

Invariant Violation: scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed, otherwise there is no way to know the location of offscreen indices or handle failures., js engine: hermes

원인: useEffect에서 Flatlist item이 랜더링 되기 전 scrollToIndex가 실행 되었기 때문

해결: onScrollToIndexFailed 함수를 추가

 	<FlatList
      ref={listRef}
      onViewableItemsChanged={onViewableItemsChanged}
      viewabilityConfig={{itemVisiblePercentThreshold: 75}}
      data={data}
      renderItem={renderItem}
      pagingEnabled={true}
      showsHorizontalScrollIndicator={false}
      onScrollToIndexFailed={onScrollToIndexFailed}
    />

0개의 댓글