sx-paginate

React JS pagination library makes pagination simple

Suboor Khan
Suboor Khan

Suboor Khan

Software Engineer

TypescriptReact

sx-paginate

NPM JavaScript Style Guide

Screenshot 2022-12-29 at 5 18 48 AM

DEMO - https://stackblitz.com/edit/react-hctxyq?file=src/App.js

Install

npm install --save sx-paginate

Usage

import React, { useState, useEffect } from 'react'

import { SxPaginate } from 'sx-paginate'
import 'sx-paginate/dist/index.css'

const App = () => {
  const [posts, setPosts] = useState([])
  const [paginatedPosts, setPaginatedPosts] = useState([])

  const onPaginate = (pageNumber: number) => {
    console.log(pageNumber)
  }

  useEffect(() => {
    (async () => {
      const res = await fetch('https://dummyjson.com/posts')
      const data = await res.json()
      setPosts(data.posts)
    })()
  }, [])

  useEffect(() => {
    console.log(paginatedPosts)
  }, [paginatedPosts])

  return (
    <>
      {paginatedPosts.map((post: any) => (
        <div key={post.id}>{post.title}</div>
      ))}

      <SxPaginate
        recordsPerPage={10}
        onPaginate={onPaginate}
        records={posts}
        setRecords={setPaginatedPosts as any}
        activeBtnStyle={{ background: 'coral' }}
      />
    </>
  )
}

export default App
HomeNews feedsWorkSessionsContact