GithubHelp home page GithubHelp logo

tarun-soni / flatlist-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beforesemicolon/flatlist-react

0.0 0.0 0.0 1.97 MB

A helpful utility component to handle lists in react like a champ

License: MIT License

JavaScript 0.68% TypeScript 99.32%

flatlist-react's Introduction

FlatList React

A helpful react utility component intended to simplify handling rendering list with ease. It can handle grouping, sorting, filtering, searching, sorting, paginating, styling with very simple props.

Build GitHub npm GitHub release (latest by date)


Dear React Native Developer

This is not intended for React-Native usage. Although some features will still work, others will just break your application. Use at your own risk.

Install

Make sure you are running react and react-dom version 16.8.0+.

npm install flatlist-react

How to use

Take in consideration the following list passed to component PeopleList:

// App.jsx
people = [
    {firstName: 'Elson', lastName: 'Correia', info: {age: 24}},
    {firstName: 'John', lastName: 'Doe', info: {age: 18}},
    {firstName: 'Jane', lastName: 'Doe', info: {age: 34}},
    {firstName: 'Maria', lastName: 'Carvalho', info: {age: 22}},
    {firstName: 'Kelly', lastName: 'Correia', info:{age: 23}},
    {firstName: 'Don', lastName: 'Quichote', info: {age: 39}},
    {firstName: 'Marcus', lastName: 'Correia', info: {age: 0}},
    {firstName: 'Bruno', lastName: 'Gonzales', info: {age: 25}},
    {firstName: 'Alonzo', lastName: 'Correia', info: {age: 44}}
  ]

  <PeopleList people={people}/>

Now inside your component file, we create a function renderPerson that will be passed to renderItem:

// PeopleList.jsx
import FlatList from 'flatlist-react';

...

renderPerson = (person, idx) => {
  return (
      <li key={idx}>
        <b>{person.firstName} {person.lastName}</b> (<span>{person.info.age}</span>)
      </li>
  );
}

...

return (
    <ul>
        <FlatList
          list={this.props.people}
          renderItem={this.renderPerson}
          renderWhenEmpty={() => <div>List is empty!</div>}
          sortBy={["firstName", {key: "lastName", descending: true}]}
          groupBy={person => person.info.age > 18 ? 'Over 18' : 'Under 18'}
        />
    </ul>
)

Full Documentation

Features Props / Components
Rendering list, renderItem, renderWhenEmpty, wrapperHtmlTag, limit, reversed
Render Optimization renderOnScroll
Pagination (Infinite Scroll) hasMoreItems, loadMoreItems, paginationLoadingIndicator, paginationLoadingIndicatorPosition
Filtering filterBy
Searching searchTerm, searchBy, searchOnEveryWord, searchMinCharactersCount, searchCaseInsensitive
Sorting sortBy, sortCaseInsensitive, sortDescending
Grouping groupOf, groupBy, groupSeparator, groupSeparatorAtTheBottom, groupReversed, groupSorted, groupSortedBy, groupSortedDescending, groupSortedCaseInsensitive
Styling displayGrid, gridGap, minColumnWidth, displayRow, rowGap
scrollToTop scrollToTopButton, scrollToTopOffset, scrollToTopPadding, scrollToTopPosition
Components PlainList
Utilities sortList, searchList, filterList, groupList, limitList

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.