New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bazhe/use-pagination

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bazhe/use-pagination

React pagination hook for handling pagination logic

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@bazhe/use-pagination

React hook for handling your pagination. Depends on: @bazhe/paginator

Playground/Demo: https://blagoj5.github.io/pagination/#playground
Full documentation: https://blagoj5.github.io/pagination

Getting Started

Prerequisites

You need to have react-dom and react above version 16

"react": ">=16.0.0",
"react-dom": ">=16.0.0"

Installing

npm

npm install @bazhe/use-pagination

yarn

yarn add @bazhe/use-pagination

Usage

Typescript usage example in: https://github.com/Blagoj5/pagination/blob/main/example/components/pagination-hook-demo.tsx

Import

import { usePagination } from '@bazhe/use-pagination';

Initialization

Syntax: usePagination(paginationOptions)
Returns: PaginationResult

export const PaginationHookDemo: React.FC = () => {
  const {
    paginationResult,
    nextPage,
    previousPage,
    setCurrentPage,
    setItems,
  } = usePagination({
    items: defaultItems,
    limit: 2,
  });

  return (
    <div>
      Pagination data:
      <pre>{JSON.stringify(paginationResult, null, 2)}</pre>
    </div>
  );
};

API

Parameters

usePagination(paginationOptions) accepts 1 parameter:

Pagination Options
NameTypeDefaultDescription
itemsT[] | undefined[]Initial items for the pagination
limitnumber | undefined4The limit of items per page
currentPagenumber | undefined1The current page
linksnumber | undefined10Links is the number of pages/links/buttons to display. Example: How many buttons you want to show in the pagination bar?
totalResultsnumber | undefineditems.lengthTotal results is the maximum number of items. Usually refers to items.length (so there's no need to pass it)

Pagination Result/Return

The result from usePagination hook:

  • paginationResult
NameTypeDescription
itemsT[] | undefinedThe items that will change depending on the pagination (currentPage, limit ...)
all_itemsT[] | undefinedInitial/All items for the pagination
total_pagesnumber | undefinedThe total pages for the provided items. Example: 12 items with limit 2 -> 6 total pages
pagesnumberThe number of pages between range(first_page, last_page)
current_pagenumberCurrent page
first_pagenumberFirst page, depends on the link (buttons/links to display in the pagination bar) and limit (items per page)
last_pagenumberLast page, depends on the link (buttons/links to display in the pagination bar) and limit (items per page)
previous_pagenumberPrevious page, current_page - 1
next_pagenumberNext page, current_page + 1
has_previous_pageboolean
has_next_pageboolean
total_resultsnumberThe length of the initial items
resultsnumberResults per page
first_resultnumberFirst result is the index of the item that's first for the current page - items[first_result] (depends on link and limit)
last_resultnumberLast result is the index of the item that's last for the current page - items[last_result] (depends on link and limit)
limitnumberThe limit of items per page

  • Pagination handlers for managing state
NameTypeDescription
setCurrentPage(n: number) => voidFunction handler for changing the current page
setItems(items: T[]) => voidFunction handler for changing the items
setPageAndItems(payload: { items: I[]; currentPage: number }) => voidFunction handler for changing current page and the items themselves
nextPage() => voidFunction handler for changing to next page
previousPage() => voidFunction handler for changing to previous page

Built With

Depends on:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Blagoj Petrov

Security

This project doesn’t have any security concerns.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

FAQs

Package last updated on 16 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc