Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#18 use current page prop before falling back to page 1 when setting initial page #30

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ function Paginator(props) {
props.setCurrentPage(currentPage);
}, [state.totalPages, props.pageLimit]);
React.useEffect(function () {
gotoPage(1);
}, [gotoPage]);
gotoPage(props.currentPage || 1);
}, [gotoPage, props.currentPage]);
React.useEffect(function () {
props.setOffset((props.currentPage - 1) * props.pageLimit);
}, [props.currentPage]);
Expand Down
4 changes: 2 additions & 2 deletions dist/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ function Paginator(props) {
props.setCurrentPage(currentPage);
}, [state.totalPages, props.pageLimit]);
useEffect(function () {
gotoPage(1);
}, [gotoPage]);
gotoPage(props.currentPage || 1);
}, [gotoPage, props.currentPage]);
useEffect(function () {
props.setOffset((props.currentPage - 1) * props.pageLimit);
}, [props.currentPage]);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-hooks-paginator",
"description": "A package for adding paginator functionality to react apps",
"version": "0.4.4",
"version": "0.5.0",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"files": [
Expand All @@ -28,8 +28,7 @@
"build": "del dist && rollup -c",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prepublish": "npm run build",
"bundle-report": "webpack-bundle-analyzer dist/stats.json"
"prepublish": "npm run build"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function Paginator(props) {
);

useEffect(() => {
gotoPage(1);
}, [gotoPage]);
gotoPage(props.currentPage || 1);
}, [gotoPage, props.currentPage]);

useEffect(() => {
props.setOffset((props.currentPage - 1) * props.pageLimit);
Expand Down
2 changes: 1 addition & 1 deletion stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -3346,7 +3346,7 @@
</script>
<script>
const chartParameters = {};
const data = {"version":1,"tree":{"name":"index.esm.js","children":[{"name":"node_modules","children":[{"name":"react-is","children":[{"name":"cjs","children":[{"name":"react-is.production.min.js","uid":"c51a-2"},{"name":"react-is.development.js","uid":"c51a-3"}]},{"name":"index.js","uid":"c51a-6"}]},{"name":"object-assign","children":[{"name":"index.js","uid":"c51a-7"}]},{"name":"prop-types","children":[{"name":"lib","children":[{"name":"ReactPropTypesSecret.js","uid":"c51a-8"}]},{"name":"checkPropTypes.js","uid":"c51a-10"},{"name":"factoryWithTypeCheckers.js","uid":"c51a-14"},{"name":"factoryWithThrowingShims.js","uid":"c51a-15"},{"name":"index.js","uid":"c51a-18"}]},{"name":"style-inject","children":[{"name":"dist","children":[{"name":"style-inject.es.js","uid":"c51a-19"}]}]}]},{"name":"src","children":[{"name":"lib","children":[{"name":"style","children":[{"name":"main.scss","uid":"c51a-20"}]},{"name":"paginator.js","uid":"c51a-21"},{"name":"index.js","uid":"c51a-22"}]}]},{"name":"\u0000rollupPluginBabelHelpers.js","uid":"c51a-0"},{"name":"\u0000commonjsHelpers.js","uid":"c51a-1"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js?commonjs-proxy","uid":"c51a-4"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js?commonjs-proxy","uid":"c51a-5"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js?commonjs-proxy","uid":"c51a-9"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js?commonjs-proxy","uid":"c51a-11"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js?commonjs-proxy","uid":"c51a-12"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js?commonjs-proxy","uid":"c51a-13"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js?commonjs-proxy","uid":"c51a-16"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js?commonjs-proxy","uid":"c51a-17"}]},"nodes":{"c51a-0":{"renderedLength":2713,"id":"\u0000rollupPluginBabelHelpers.js"},"c51a-1":{"renderedLength":255,"id":"\u0000commonjsHelpers.js"},"c51a-2":{"renderedLength":4294,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js"},"c51a-3":{"renderedLength":10328,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js"},"c51a-4":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js?commonjs-proxy"},"c51a-5":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js?commonjs-proxy"},"c51a-6":{"renderedLength":198,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js"},"c51a-7":{"renderedLength":2094,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js"},"c51a-8":{"renderedLength":310,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js"},"c51a-9":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js?commonjs-proxy"},"c51a-10":{"renderedLength":3577,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js"},"c51a-11":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js?commonjs-proxy"},"c51a-12":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js?commonjs-proxy"},"c51a-13":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js?commonjs-proxy"},"c51a-14":{"renderedLength":21224,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js"},"c51a-15":{"renderedLength":1366,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js"},"c51a-16":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js?commonjs-proxy"},"c51a-17":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js?commonjs-proxy"},"c51a-18":{"renderedLength":911,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/index.js"},"c51a-19":{"renderedLength":636,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/style-inject/dist/style-inject.es.js"},"c51a-20":{"renderedLength":938,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/style/main.scss"},"c51a-21":{"renderedLength":6333,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/paginator.js"},"c51a-22":{"renderedLength":0,"isEntry":true,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/index.js"},"c51a-23":{"renderedLength":0,"isExternal":true,"id":"react"}},"links":[{"source":"c51a-22","target":"c51a-21"},{"source":"c51a-21","target":"c51a-0"},{"source":"c51a-21","target":"c51a-23"},{"source":"c51a-21","target":"c51a-18"},{"source":"c51a-21","target":"c51a-20"},{"source":"c51a-18","target":"c51a-1"},{"source":"c51a-18","target":"c51a-6"},{"source":"c51a-18","target":"c51a-14"},{"source":"c51a-18","target":"c51a-15"},{"source":"c51a-18","target":"c51a-11"},{"source":"c51a-18","target":"c51a-16"},{"source":"c51a-18","target":"c51a-17"},{"source":"c51a-20","target":"c51a-19"},{"source":"c51a-6","target":"c51a-1"},{"source":"c51a-6","target":"c51a-2"},{"source":"c51a-6","target":"c51a-3"},{"source":"c51a-6","target":"c51a-4"},{"source":"c51a-6","target":"c51a-5"},{"source":"c51a-14","target":"c51a-6"},{"source":"c51a-14","target":"c51a-7"},{"source":"c51a-14","target":"c51a-8"},{"source":"c51a-14","target":"c51a-10"},{"source":"c51a-14","target":"c51a-11"},{"source":"c51a-14","target":"c51a-12"},{"source":"c51a-14","target":"c51a-9"},{"source":"c51a-14","target":"c51a-13"},{"source":"c51a-15","target":"c51a-8"},{"source":"c51a-15","target":"c51a-9"},{"source":"c51a-11","target":"c51a-6"},{"source":"c51a-16","target":"c51a-14"},{"source":"c51a-17","target":"c51a-15"},{"source":"c51a-2","target":"c51a-1"},{"source":"c51a-3","target":"c51a-1"},{"source":"c51a-4","target":"c51a-2"},{"source":"c51a-5","target":"c51a-3"},{"source":"c51a-10","target":"c51a-8"},{"source":"c51a-10","target":"c51a-9"},{"source":"c51a-12","target":"c51a-7"},{"source":"c51a-9","target":"c51a-8"},{"source":"c51a-13","target":"c51a-10"}]};
const data = {"version":1,"tree":{"name":"index.cjs.js","children":[{"name":"node_modules","children":[{"name":"react-is","children":[{"name":"cjs","children":[{"name":"react-is.production.min.js","uid":"934d-2"},{"name":"react-is.development.js","uid":"934d-3"}]},{"name":"index.js","uid":"934d-6"}]},{"name":"object-assign","children":[{"name":"index.js","uid":"934d-7"}]},{"name":"prop-types","children":[{"name":"lib","children":[{"name":"ReactPropTypesSecret.js","uid":"934d-8"}]},{"name":"checkPropTypes.js","uid":"934d-10"},{"name":"factoryWithTypeCheckers.js","uid":"934d-14"},{"name":"factoryWithThrowingShims.js","uid":"934d-15"},{"name":"index.js","uid":"934d-18"}]},{"name":"style-inject","children":[{"name":"dist","children":[{"name":"style-inject.es.js","uid":"934d-19"}]}]}]},{"name":"src","children":[{"name":"lib","children":[{"name":"style","children":[{"name":"main.scss","uid":"934d-20"}]},{"name":"paginator.js","uid":"934d-21"},{"name":"index.js","uid":"934d-22"}]}]},{"name":"\u0000rollupPluginBabelHelpers.js","uid":"934d-0"},{"name":"\u0000commonjsHelpers.js","uid":"934d-1"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js?commonjs-proxy","uid":"934d-4"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js?commonjs-proxy","uid":"934d-5"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js?commonjs-proxy","uid":"934d-9"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js?commonjs-proxy","uid":"934d-11"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js?commonjs-proxy","uid":"934d-12"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js?commonjs-proxy","uid":"934d-13"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js?commonjs-proxy","uid":"934d-16"},{"name":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js?commonjs-proxy","uid":"934d-17"}]},"nodes":{"934d-0":{"renderedLength":2713,"id":"\u0000rollupPluginBabelHelpers.js"},"934d-1":{"renderedLength":255,"id":"\u0000commonjsHelpers.js"},"934d-2":{"renderedLength":4294,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js"},"934d-3":{"renderedLength":10328,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js"},"934d-4":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.production.min.js?commonjs-proxy"},"934d-5":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/cjs/react-is.development.js?commonjs-proxy"},"934d-6":{"renderedLength":198,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js"},"934d-7":{"renderedLength":2094,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js"},"934d-8":{"renderedLength":310,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js"},"934d-9":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/lib/ReactPropTypesSecret.js?commonjs-proxy"},"934d-10":{"renderedLength":3577,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js"},"934d-11":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/react-is/index.js?commonjs-proxy"},"934d-12":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/object-assign/index.js?commonjs-proxy"},"934d-13":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/checkPropTypes.js?commonjs-proxy"},"934d-14":{"renderedLength":21224,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js"},"934d-15":{"renderedLength":1366,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js"},"934d-16":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithTypeCheckers.js?commonjs-proxy"},"934d-17":{"renderedLength":0,"id":"\u0000/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/factoryWithThrowingShims.js?commonjs-proxy"},"934d-18":{"renderedLength":911,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/prop-types/index.js"},"934d-19":{"renderedLength":636,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/node_modules/style-inject/dist/style-inject.es.js"},"934d-20":{"renderedLength":938,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/style/main.scss"},"934d-21":{"renderedLength":6490,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/paginator.js"},"934d-22":{"renderedLength":0,"isEntry":true,"id":"/Users/patricknwakwoke/Documents/programming/oss/react-paginator/src/lib/index.js"},"934d-23":{"renderedLength":0,"isExternal":true,"id":"react"}},"links":[{"source":"934d-22","target":"934d-21"},{"source":"934d-21","target":"934d-0"},{"source":"934d-21","target":"934d-23"},{"source":"934d-21","target":"934d-18"},{"source":"934d-21","target":"934d-20"},{"source":"934d-18","target":"934d-1"},{"source":"934d-18","target":"934d-6"},{"source":"934d-18","target":"934d-14"},{"source":"934d-18","target":"934d-15"},{"source":"934d-18","target":"934d-11"},{"source":"934d-18","target":"934d-16"},{"source":"934d-18","target":"934d-17"},{"source":"934d-20","target":"934d-19"},{"source":"934d-6","target":"934d-1"},{"source":"934d-6","target":"934d-2"},{"source":"934d-6","target":"934d-3"},{"source":"934d-6","target":"934d-4"},{"source":"934d-6","target":"934d-5"},{"source":"934d-14","target":"934d-6"},{"source":"934d-14","target":"934d-7"},{"source":"934d-14","target":"934d-8"},{"source":"934d-14","target":"934d-10"},{"source":"934d-14","target":"934d-11"},{"source":"934d-14","target":"934d-12"},{"source":"934d-14","target":"934d-9"},{"source":"934d-14","target":"934d-13"},{"source":"934d-15","target":"934d-8"},{"source":"934d-15","target":"934d-9"},{"source":"934d-11","target":"934d-6"},{"source":"934d-16","target":"934d-14"},{"source":"934d-17","target":"934d-15"},{"source":"934d-2","target":"934d-1"},{"source":"934d-3","target":"934d-1"},{"source":"934d-4","target":"934d-2"},{"source":"934d-5","target":"934d-3"},{"source":"934d-10","target":"934d-8"},{"source":"934d-10","target":"934d-9"},{"source":"934d-12","target":"934d-7"},{"source":"934d-9","target":"934d-8"},{"source":"934d-13","target":"934d-10"}]};

document.addEventListener('DOMContentLoaded', () => {
const width = chartParameters.width || window.innerWidth;
Expand Down