0.1.32 • Published 3 years ago

@protonko/section-list v0.1.32

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

SectionList

npm version npm size

Component for rendering sectioned lists for plain React. Created by analogy with React Native SectionList.

Demo Code example

npm.io

Installation

The package can be installed via npm:

npm install @protonko/section-list

Or via yarn:

yarn add @protonko/section-list

You’ll need to install react and react-dom separately since those dependencies aren’t included in the package.

Support

  • React 17.0.0 or newer

Usage

import React from 'react';
import {Section, SectionList} from '@protonko/section-list'

interface ExampleData {
  id: number,
  title: string,
  description: string,
  // ...any attributes
}

const sections: Section<ExampleData> = [{
  title: 'Section 1',
  data: [{id: 1, title: 'title 1', description: 'descr'}]
}]

const Example = () => {
  const keyExtractor = (item: ExampleData) => item.id
  
  const renderItem = (elem: ExampleData) => (
    <article>
      <h2>{elem.title}</h2>
      <p>{elem.description}</h2>
    </article>
  )
  
  return (
    <SectionList<ExampleData>
      keyExtractor={keyExtractor}
      renderItem={renderItem}
      sections={sections}
    />
  )
}

Props

The component expects a generic-type T that describes section data.

NameDescriptionTypeRequired
keyExtractorUsed to extract a unique key for a given item at the specified index.(item: T, index: number) => stringyes
renderItemDefault renderer for every item in every section.(value: T, index: number, array: T[]) => ReactNode,yes
sectionsThe actual data to render.{title: string, data: T[]}[]yes
classNameUsed to override a component's styles using custom classes.stringno
onEndReachedCalled once when the scroll position gets within onEndReachedThreshold of the rendered content.() => voidno
onEndReachedThresholdHow far from the end the bottom edge of the list must be from the end of the content to trigger the onEndReached callback.numberno
renderSectionHeaderRendered at the top of each section.(section: {title: string, data: T[]}) => ReactNodeno
shouldLoadDataIndicated whether to create an IntersectionObserver.booleanno
ListEmptyComponentRendered when the list is empty.ReactElementno
ListFooterComponentRendered at the very end of the list.ReactElementno
0.1.32

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.28

3 years ago

0.1.27

3 years ago

0.1.26

3 years ago

0.1.25

3 years ago

0.1.24

3 years ago

0.1.23

3 years ago

0.1.22

3 years ago

0.1.21

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago