picpagination.tsx 760 Bytes
Newer Older
백승민's avatar
백승민 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from "react";

type num = {
    total: number, 
    page: number, 
    setPage: Function
}

export default function Pagination ({total, page, setPage} : num) {
    const numPages = Math.ceil(total / 15);

    return (
        <div>
            <button onClick={() => setPage(page - 1)} disabled={page === 1}>
                &lt;
            </button>

            {Array(numPages)
                .fill(1)
                .map((_, i) => (
                    <button key={i + 1} onClick={() => setPage(i + 1)}>
                        {i + 1}
                    </button>
                ))}

            <button onClick={() => setPage(page + 1)} disabled={page === numPages}>
                &gt;
            </button>
        </div>
    );
};