Skip to content

Paginate each sub component automatically. Implemented in React hooks so we can ship the compoenent without extra dependency like redux.

Notifications You must be signed in to change notification settings

kfwong/react-paginated-form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PaginatedForm

Paginate each sub component automatically. Implemented in React hooks so we can ship the compoenent without extra dependency like redux.

Usage:

  1. Putting any components into children of PaginatedForm will automatically paginate them.
// you can use onChangePage to customize pagination behaviour such as conditionally skip page
const logPage = (oldPage, newPage) => {
    if(newPage === 1) return 2;
    return newPage;
}

<PaginatedForm
      titles={["Page0", "Page1", "Page2", "Page3"]}
      onChangePage={logPage}
    >
      <Page0/>
      <Page1/>
      <Page2/>
      ...
</PaginatedForm>
  1. To customize paginated control, optionally import usePaginatedFormControl and destructure it for the methods.
import {usePaginatedFormControl} from "./PaginatedForm";

export const Page1: React.FC = (props) => {
  const { nextPage, previousPage, gotoPage } = usePaginatedFormControl();

  return (
    <>
      <h1>Page 1</h1>
      <p>This is page 1 description.</p>
      <button onClick={previousPage}>Previous</button>
      <button onClick={nextPage}>Next</button>
    </>
  );
}

About

Paginate each sub component automatically. Implemented in React hooks so we can ship the compoenent without extra dependency like redux.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published