File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
app/javascript/components Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { useState } from 'react'
2
2
import { GetUsersResponse } from '../generated_types/users'
3
3
import PaginationLinks from './pagination'
4
+ import getApi from '../utils/get_api'
4
5
5
6
const Users = ( { pagination : initialPagination , users : initialUsers } : GetUsersResponse ) => {
6
7
const [ pagination , setPagination ] = useState ( initialPagination )
7
8
const [ users , setUsers ] = useState ( initialUsers )
8
9
10
+ // this methods loads the requested page & re-renders
11
+ // the table/pagination using it
12
+ const loadPage = async ( pageNumber : number ) => {
13
+ const response = await getApi ( `/users?page=${ pageNumber } ` )
14
+ setUsers ( response . users )
15
+ setPagination ( response . pagination )
16
+ }
17
+
9
18
return (
10
19
< >
11
20
< table >
@@ -26,7 +35,7 @@ const Users = ({ pagination: initialPagination, users: initialUsers }: GetUsersR
26
35
) ) }
27
36
</ tbody >
28
37
</ table >
29
- < PaginationLinks onPageChanged = { newPage => { } } { ...pagination } />
38
+ < PaginationLinks onPageChanged = { newPage => loadPage ( newPage ) } { ...pagination } />
30
39
</ >
31
40
)
32
41
}
You can’t perform that action at this time.
0 commit comments