Add Header to FlatList in React Native | ListHeaderComponent

Hello friends, In today’s tutorial we would learn about implementing header component on FlatList in react native. Header component shows just at top side of FlatList before it’s first item. The main purpose of header is to display List title or about list. In react native the FlatList has a prop named as ListHeaderComponen={} which can render given component as header of FlatList. There are also a prop named as ListHeaderComponentStyle={} which is used to apply custom styling on header. We would discuss them both in our tutorial. So in this tutorial we would learn about Add Header to FlatList in React Native.

Contents in this project Add Header to FlatList in React Native | ListHeaderComponent :-

1. Open your project’s main App.js file and import View, StyleSheet, SafeAreaView, FlatList and Text component.

2. Creating our main functional component named as App.

3. Creating a Constant Array named as BirdsName. We would display all of these items as FlatList items.

4. Creating a component named as ItemRender with name prop. We would use this prop to render list items.

5. Creating another component named as ItemDivider. We would use this component to render separator line between list items.

6. Creating a Custom component named as FlatList_Header. This is our header component.

7. Creating return() block, Now here we would make our FlatList component with ListHeaderComponent and ListHeaderComponentStyle prop. We’re calling the FlatList_Header component in ListHeaderComponent prop.

8. Creating Style.

9. Complete Source Code for App.js File :-

Screenshot :-

Add Header to FlatList in React Native | ListHeaderComponent

Leave a Reply

Your email address will not be published. Required fields are marked *