From f6aec34f337797255085df2483931b14685ca150 Mon Sep 17 00:00:00 2001 From: Daniel Kuhn Date: Wed, 31 Jan 2024 15:12:34 +0100 Subject: [PATCH] fix: prevent rerender of ListHeaderComponent Instead of creating an anonymous function for the ListHeaderComponent prop (which is a new component on every render, causing it to get unmounted and remounted on every render) render the children as an Element. According to the documentation of RN FlatList (https://reactnative.dev/docs/flatlist#listheadercomponent), the ListHeaderComponent can be a function OR an Element. Changing this to element stops the rerenders. --- src/ScrollView/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScrollView/index.tsx b/src/ScrollView/index.tsx index 134ecd5..355296e 100644 --- a/src/ScrollView/index.tsx +++ b/src/ScrollView/index.tsx @@ -10,7 +10,7 @@ const ScrollViewComponent: Props = (props) => { keyExtractor={(_e, i) => 'dom' + i.toString()} ListEmptyComponent={null} renderItem={null} - ListHeaderComponent={() => <>{props.children}} + ListHeaderComponent={<>{props.children}} /> ); };