MCPcopy Create free account
hub / github.com/callstack/react-native-paper / DataTableExample

Function DataTableExample

example/src/Examples/DataTableExample.tsx:15–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13}>;
14
15const DataTableExample = () => {
16 const [sortAscending, setSortAscending] = React.useState<boolean>(true);
17 const [page, setPage] = React.useState<number>(0);
18 const [items] = React.useState<ItemsState>([
19 {
20 key: 1,
21 name: 'Cupcake',
22 calories: 356,
23 fat: 16,
24 },
25 {
26 key: 2,
27 name: 'Eclair',
28 calories: 262,
29 fat: 16,
30 },
31 {
32 key: 3,
33 name: 'Frozen yogurt',
34 calories: 159,
35 fat: 6,
36 },
37 {
38 key: 4,
39 name: 'Gingerbread',
40 calories: 305,
41 fat: 3.7,
42 },
43 {
44 key: 5,
45 name: 'Ice cream sandwich',
46 calories: 237,
47 fat: 9,
48 },
49 {
50 key: 6,
51 name: 'Jelly Bean',
52 calories: 375,
53 fat: 0,
54 },
55 ]);
56 const [numberOfItemsPerPageList] = React.useState([2, 3, 4, 200]);
57 const [itemsPerPage, onItemsPerPageChange] = React.useState(
58 numberOfItemsPerPageList[0]
59 );
60 const sortedItems = items
61 .slice()
62 .sort((item1, item2) =>
63 sortAscending
64 ? item1.name.localeCompare(item2.name)
65 : item2.name.localeCompare(item1.name)
66 );
67 const from = page * itemsPerPage;
68 const to = Math.min((page + 1) * itemsPerPage, items.length);
69
70 React.useEffect(() => {
71 setPage(0);
72 }, [itemsPerPage]);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…