1.0.34 • Published 6 months ago

react-pagination-helper v1.0.34

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

inq5erdiagram inq5erdiagram

<!-- app file -->

import { useState } from 'react';
import {SimplePaginationHelper} from 'react-pagination-helper'

function App() {

  const [active, setActive] = useState(1);
  const [perPage, setPerPage] = useState(10);
  const perPageList = [10, 25, 50, 100, 200, 300]
  const totalNumber = 178;
  const paginationStyle = {
    container: {},
    perPageContainer: {},
    perPageSelect: {},
    paginationContainer: {},
    doubleArrowIconDiv: {},
    doubleArrow: {},
    singleArrowIconDiv: {},
    singleArrow: {},
    itemContainer: {},
    threeDots: {},
    item: {},
    itemActive: {
      backgroundColor: 'red',
    },
  }

  return (
    <div className="App">
      <SimplePaginationHelper activePage={active} totalNumber={totalNumber}
       perPage={perPage} setPerPage={setPerPage} setActive={setActive}
       perPageList={perPageList} paginationStyle={paginationStyle} />
    </div>
  );
}

export default App;

----------For Better Version----------

<!-- app file -->

import { useState } from 'react';
import {SimplePaginationHelper} from 'react-pagination-helper'

function App() {

  const perPageList = [10, 25, 50, 100, 200, 300]
  const [paginationValue, setPaginationValue] = useState({
    page: 1,
    per_page: perPageList[0],
    total: 0,
  });
   async function setPerPage(perPage) {
    setPaginationValue({
      ...paginationValue,
      per_page: perPage,
    });
    await fetchData(paginationValue.page, perPage);
  }
  async function setActive(activePage) {
    setPaginationValue({
      ...paginationValue,
      page: activePage,
    });
    await fetchData(activePage, paginationValue.per_page);
  }

  useEffect(() => {
    fetchData(paginationValue.page, paginationValue.per_page);
  }, []);

  const fetchData = (page, per_page) => {
   // this code depends on api response
    axios
      .get(`${serverUrl}/user/list?page=${page}&per_page=${per_page}`)
      .then((res) => {
        setCompanyData(res?.data?.data?.user?.data);
        setPaginationValue({
          page: res?.data?.data?.user?.current_page,
          per_page: res?.data?.data?.user?.per_page,
          total: res?.data?.data?.user?.total,
        });
      })
      .catch((error) => {
        toast.error("Something went wrong");
        console.log(error);
      });
  };

   // for change style must me follow and debug user html code in console for inspect
  const paginationStyle = {
    container: {},
    perPageContainer: {},
    perPageSelect: {},
    paginationContainer: {},
    doubleArrowIconDiv: {},
    doubleArrow: {},
    singleArrowIconDiv: {},
    singleArrow: {},
    itemContainer: {},
    threeDots: {},
    item: {},
    itemActive: {
      backgroundColor: 'red',
    },
  }

  return (
    <div className="App">
      <SimplePaginationHelper
      activePage={paginationValue.page}
      totalNumber={paginationValue?.total}
      perPage={paginationValue.per_page}
      setPerPage={setPerPage}
      setActive={setActive}
      perPageList={perPageList}
      paginationStyle={paginationStyle} />
    </div>
  );
}

export default App;
1.0.33

6 months ago

1.0.34

6 months ago

1.0.29

6 months ago

1.0.32

6 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.28

8 months ago

1.0.27

8 months ago

1.0.26

8 months ago

1.0.25

8 months ago

1.0.24

8 months ago

1.0.23

8 months ago

1.0.22

8 months ago

1.0.21

8 months ago

1.0.20

8 months ago

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago