配合蚂蚁列表组件,这个分页组件一般只用来做页面局部的刷新。
import router from 'next/router'; import { Pagination as AntPagination, PaginationProps } from 'antd'; import RightContainer from "./rightcontainer"; import { useUrlSearchParams } from "use-url-search-params"; export default function Pagination({ onChange, ...rest }: PaginationProps) { const [, setParams] = useUrlSearchParams({}, { page: Number }); return <RightContainer> <AntPagination {...rest} onChange={(p, s) => { setParams({ ...router.query, page: p }); onChange && onChange(p, s); }} /> </RightContainer>; }
import { ReactNode } from "react"; export default function RightContainer({ children }: { children: ReactNode; }) { return <><div className='c'>{children}</div> <style jsx>{` .c{ margin-top: 2rem; display: flex; justify-content: flex-end; } `}</style> </>; }