I'm trying to get the height with onLayout but the getItemLayout run first the onLoad and write this error [Unhandled promise rejection: Invariant Violation: [5063,"RCTView",911,{"height":"<>"}] is not usable as a native method argument]
How can I get the height before the getItemLayout runs ?
const [size, setSize] = useState([]);
const renderItemFinal = useCallback(({ item, index }) => {
return (
<View
style={{ flex: 1 }}>
<Post
postAtivo={false}
onViewRef={itemState?.item?.post_id == item?.post_id && itemState?.isViewable && ready ? true : false}
user={item.user}
page={item.page}
item={item}
/>
</View>
)
}, [itemState])
const getItemLayout = (data, index) => {
const length = size[index];
const offset = size.slice(0, index).reduce((a, c) => a + c, 0)
return { length, offset, index }
}
<FlatList
getItemLayout={getItemLayout}
ref={flatlistRed}
showsVerticalScrollIndicator={false}
onViewableItemsChanged={onViewRef.current}
viewabilityConfig={viewConfigRef.current}
data={posts}
windowSize={5}
initialNumToRender={5}
refreshControl={refreshControlJsx}
onEndReachedThreshold={0.2}
onEndReached={endReached}
ListEmptyComponent={empty}
renderItem={renderItemFinals}
keyExtractor={keyExtractor}
decelerationRate={'normal'}
ListFooterComponent={footerJsx}
removeClippedSubviews={Platform.OS === 'ios' ? false : true}
/>