refactor: Refactor usePagination hook to include useEffect

This commit is contained in:
yoosangwook 2024-10-17 13:34:11 +09:00
parent 63b500e0c0
commit 429832b8b7

View File

@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
/**
* 페이지네이션
@ -14,6 +14,10 @@ const usePagination = ({ pageNo = 1, pageSize = 10, pagePerBlock = 10, totalCoun
setCurrentPage(page)
}
useEffect(() => {
setCurrentPage(pageNo)
}, [pageNo])
const pageGroup = Math.floor((currentPage - 1) / pagePerBlock) + 1
const totalPages = Math.ceil(totalCount / pageSize)
const pages = Array.from({ length: totalPages }, (_, i) => i + 1)