11import { useRouter } from 'next/router'
22import { useCallback } from 'react'
33
4- import { UseSearchAndPagination } from './types'
4+ import { IndexType , IUseSearchAndPagination } from './types'
55import { convert } from './utils'
66
77function getSingleParameterValue (
@@ -10,7 +10,10 @@ function getSingleParameterValue(
1010 return Array . isArray ( parameter ) ? parameter [ 0 ] : parameter
1111}
1212
13- export function useSearchAndPagination ( ) : UseSearchAndPagination {
13+ export const useSearchAndPagination : IUseSearchAndPagination = function (
14+ config
15+ ) {
16+ const { indexType = IndexType . ZERO_BASED , pageSize = 15 } = config || { }
1417 const router = useRouter ( )
1518
1619 const setPage = useCallback (
@@ -60,8 +63,11 @@ export function useSearchAndPagination(): UseSearchAndPagination {
6063
6164 return {
6265 search : getSingleParameterValue ( router . query . search ) || '' ,
63- page : convert ( getSingleParameterValue ( router . query . page ) || null , 0 ) ,
64- size : convert ( getSingleParameterValue ( router . query . size ) || null , 15 ) ,
66+ page : convert (
67+ getSingleParameterValue ( router . query . page ) || null ,
68+ indexType === IndexType . ZERO_BASED ? 0 : 1
69+ ) ,
70+ size : convert ( getSingleParameterValue ( router . query . size ) || null , pageSize ) ,
6571 actions : {
6672 search,
6773 clear,
0 commit comments