2.0.2 • Published 5 years ago

react-sanity-pagination v2.0.2

Weekly downloads
49
License
MIT
Repository
github
Last release
5 years ago

🌵React Sanity Pagination

React pagination for Sanity.io

NPM JavaScript Style Guide

Install

npm install --save react-sanity-pagination

Demo

Edit React Sanity Pagination 🌵

Basic Usage

import React, { useState, useEffect } from "react";
// Import Pagination
import Pagination from "react-sanity-pagination";
// Import Querying tool
import client from "./sanity";

// Create an array outside of your component, this is done so the initial data never changes
const itemsToSend = [];
const Example = () => {
  // Create a variable for the amount of posts you want per page
  const postsPerPage = 3;
  // Create state which will be updated every time you paginate
  const [items, setItems] = useState([]);

  // Fetch all data on load
  useEffect(() => {
    client.fetch('*[_type == "dummyData"] | order(_createdAt) ').then(res => {
      // Push your data to the static array
      itemsToSend.push(...res);
    });
  }, []);

  // Create an action which will be called on paginate
  // This will return the current Page, Range of items and the Items to render
  const action = (page, range, items) => {
    console.log(page, range, items);
    // Update State
    setItems(items);
  };

  return (
    <div className="App">
      <h1>
        React Sanity Pagination Example{" "}
        <span aria-label="🌵" role="img">
          🌵
        </span>
      </h1>
      // Map through your data
      <div className="paginationContent">
        {items.map((item, index) => {
          return <div key={index}>{item.name}</div>;
        })}
      </div>
      // Assign your props // Required props: action, items, postsPerPage
      <Pagination
        items={itemsToSend}
        action={action}
        postsPerPage={postsPerPage}
      />
    </div>
  );
};

export default Example;

Props

NameRequiredType
actionYesFunction
postsPerPageYesNumber
postsLengthYesNumber
paginationStyleNo("default", "activePage", "centerMode)
nextButtonNoBoolean
nextButtonLabelNoString
prevButtonNoBoolean
prevButtonLabelNoString
jumpStartButtonNoBoolean
jumpStartButtonLabelNoString
jumpEndButtonNoBoolean
jumpEndButtonLabelNoString
jumpFiveForwardButtonNoBoolean
jumpFiveForwardButtonLabelNoString
jumpTenForwardButtonNoBoolean
jumpTenForwardButtonLabelNoString
jumpFiveBackwardButtonNoBoolean
jumpFiveBackwardButtonLabelNoString
jumpTenBackwardButtonNoBoolean
jumpTenBackwardButtonLabelNoString
classNameNoString

Pagination Styles

Default

alt text

activePage

alt text

centerMode

alt text

License

MIT © dane-brown

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago