EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

React Native SectionList

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » React Native Tutorial » React Native SectionList

react native sectionlist

Definition of React Native SectionList

React native SectionList is used to represent list data item in the form of sections, these sections can be names of various department or the categories of the various product, Basically, SectionList has few great features which will be very hard to design with any plain components like it has the ability to find start of any new section, end of any new section and if list is empty or list ended than it has beautiful function to get it (we can also write customizes css for each section for create differences between each section). We will understand more in the example.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

<SectionList
sections={[
{title: 'name of title to display here(title1)', data: [Array of data will be here to display it in the form of section]},
{title: 'name of title1 to display here (title2)', data: [Array of data will be here to display it in the form of section]}
renderItem={({item}) =>”display each item of the data of value passed to sections part”}
renderSectionHeader={({section}) => We use this section to display something on each section as the header of the section , it can be name of the section }
renderSectionFooter={({section}) => We use this section to display something on each section as the footer of the section , it can be name of the section any static attribute for footer }
keyExtractor={(item, index) =>Extract the unique index value(index)}
/>

Attributes of React Native SectionList

Following are the attributes of react native sectionlist:

1. sections

A section is a portion where we pass our all data array of objects which will contain data in the form of an array. This section is responsible to contain our data in the form of multiple arrays of objects with various names.

2. renderItem

This attribute is responsible to retrieve and extract each element of array data comet to the section portion. Basically to represent data for each item it used. We can also do some customized design for each element in this section. For example, suppose we have to display marks of the students and we want to add 5 marks to some specific student marks than we can check that student here and add the extra marks to it.

3. initialNumToRender

In this section, we manage the data which is going to display for the first time when the page will be lead. This section is very important for the react power booster. It will be an integer value. If we do not pass any number it will take 21 as the default number.

4. keyExtractor

This attribute will be used to fetch a unique id from the given item. This unique number can be item.key as the default. We can perform any activity on a particular item if we will be able to fetch the item’s unique key.

Popular Course in this category
React JS Redux Training (1 Course, 5 Projects)1 Online Courses | 5 Hands-on Projects | 18+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,487 ratings)
Course Price

View Course

Related Courses

5. renderSectionHeader

We saw that we are creating the sections in these cases, so what if we wanted to show something on the top of each section? We can use the render sectionHeader. For example, if we have many departments and each department is sectional and we want to display department names on the top of each section then we can use this attribute by defining title.

6. renderSectionFooter

In the same way renderSectionHeader, we can use renderSectionFooter to display something on the bottom of each section. For example, if we have many departments and each department is a sectional and we want to display department names on the bottom of each section then we can use this attribute by defining title and each title will be displayed at the bottom of each section.

7. onRefresh

It will be helpful to get a standard RefreshControl, and this RefreshControl will be taken for “Pull to Refresh” features. While implementing this feature make sure that these things have been implemented properly to props.

8. extraData

Rendering we know how to react native, here, in this case, suppose in some case we wanted to re-render some of our items then we can use this attribute. Basically it is using pureComponent in it.

9. onEndReached

You are scrolling your list of items and it ended, now if you wanted to do something at the end of the page content(at the time it reached threshold value )? We will use the onEndReached attribute of the react component to deal with this situation.

10. ListHeaderComponent

This will be used to render anything at the beginning of the list.

11. SectionSeparatorComponent

It will be used in case we wanted to have rendered at the top as well as the bottom of every section. In is not like IteemSeperatorComponent because itemSeperatorCoponent is used to separate items only. React added this attribute to separate it from any header.

12. stickySectionHeadersEnabled

This attribute will be used to fix our header section on scrolling. For example, many times if the list is very big and there are too many scrolling of the list, in that case, it would be better to stick the header on scrolling. This sticky header will be visible till next header arrival.

13. ListEmptyComponent

Many times it is possible that the list is empty, so how will we know and perform certain things if the list is empty? We can use ListEmptyComponent to do something in case the list of items is empty.

Examples to Implement React Native SectionList

In this example, we are displaying the list of departments along with department details. Here each department name is the section and we are displaying the names of each department on the top of each section. Please see the example and screen.

Code:

import React, { Component } from "react";
import { AppRegistry, StyleSheet, SectionList, Text, View } from "react-native";
export default class DepartmentSection extends Component {
render() {
return (
<View style={styles.containerStle}>
<SectionList
sections={[
{
title: "Account",
data: ["Ranjan", "Ajay", "vijay", "Suresh", "Anish"] },
{
title: "HR",
data: ["Kameshwar", "Ramana", "Anjali", "Reddy", "Jones"] },
{
title: "Admin",
data: ["Kriss", "Sudhir", "Ankita", "Brajesh", "Karan"] },
{
title: "IT",
data: ["Diwakar", "Raju", "Gagan", "Subodh", "Randhir"] },
{
title: "IT",
data: ["Ranjana", "Rajnish", "Poonam", "Goswami", "Rishikesh"] },
{
title: "Finance",
data: ["Alka", "Kiran", "Pinky", "Anshu", "Peyush"] },
{
title: "Sales",
data: ["Ankita", "Rehana", "Drishti", "Ayan", "Arav"] }
]}
renderItem={({ item }) => (
<Text style={styles.itemStyle}>{item}</Text>
)}
renderSectionHeader={({ section }) => (
<Text style={styles.sectionHeaderStyle}>{section.title}</Text>
)}
keyExtractor={(employee, position) => position}
/>
</View>
);
}
}
const styles = StyleSheet.create({
containerStyle: {
backgroundColor: "green",
flex: 1
},
sectionHeaderStyle: {
paddingTop: 2,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 2,
fontSize: 22,
fontWeight: "white",
color: "#fff",
backgroundColor: "#8fb1aa"
},
itemStyle: {
padding: 10,
fontSize: 18,
height: 44
}
});
// registering our department class and if we are using create react then we should skip this step
AppRegistry.registerComponent("AwesomeProject", () => DepartmentSection);

Output:

React Native SectionList-1.1

Recommended Articles

This is a guide to React Native SectionList. Here we discuss the definition and attributes of react native sectionlist along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. React Native Layout
  2. Button in React Native
  3. React Native State
  4. React Native StatusBar

React JS Redux Training (1 Course, 4 Projects)

1 Online Courses

5 Hands-on Projects

18+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
React Native Tutorial
  • Basic
    • What is React Native?
    • React Versions
    • React Constructor
    • React Native Architecture
    • React Native Libraries
    • React Components Libraries
    • React Native Components
    • React Component Library
    • React Component Lifecycle
    • React Native Framework
    • React Higher Order Component
    • React Ternary Operator
    • React Native Charts
    • React Native Layout
    • React Native Grid
    • React Native Fetch
    • React Native Modal
    • React Native SVG
    • Button in React Native
    • React List Components
    • React Native Element
    • React Native FlatList
    • React Native SectionList
    • react native dropdown
    • React Native Menu
    • React Native State
    • React State Management
    • React Native Tabs
    • React Native Tab Bar
    • React Format
    • React-Native Switch
    • React Native Firebase
    • React Native Flexbox
    • React Native StatusBar
    • React Native ScrollView
    • React Native ListView
    • React Native TextInput
    • React Native Table
    • React-Native Border Style
    • React Native Search Bar
    • React-Native StyleSheet
    • React Native Vector Icons
    • React Native Login Screen
    • React Native Splash Screen
    • React Native Image Picker
    • React Native Navigation
    • React Native Swift
    • React Controlled Input
    • React Fragment
    • React Native Color
    • React Portals
    • React Refs
    • React shouldComponentUpdate()
    • React ComponentDidMount()
    • React componentWillUpdate()
    • React Native Orientation
    • React Native Animation
    • React Native Form
    • React Props
    • React Native Linear Gradient
    • React Native AsyncStorage
    • React Error Boundaries
    • React Native Progress Bar
    • React-Native Calendar
    • React Native Linking
    • React Native DatePicker
    • React Native Image
    • React Native Drawer
    • React Native Drawer Navigation
    • React Native Fonts
    • React Native Overlay
    • React Native OneSignal
    • React Native Template
    • React Native Router
    • React Router Transition
    • React Dispatcher
    • React Native Redux
    • React JSX
    • React native keyboardavoidingview
    • React Native Permissions
    • React Redux Connect
    • React Native Material
    • React Native Gesture Handler
    • React Native Theme
    • React Native Accessibility
    • React Native Justify Content
    • MobX React Native
    • React Native Authentication
    • React Native UUID
    • React Native Geolocation
    • React Native Debugger
    • React Native Carousel
    • React Native Local Storage
    • React Native TypeScript
    • React Bootstrap
    • React Native SQLite
    • React Native Interview Questions
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - React JS Redux Training (1 Course, 4 Projects) Learn More