mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Merge branch 'data-table' into dev
# Conflicts: # src/components/messages.js
This commit is contained in:
commit
92ccc64e47
12 changed files with 206 additions and 37 deletions
13
src/components/hooks/useDataTable.js
Normal file
13
src/components/hooks/useDataTable.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { useState } from 'react';
|
||||
import { usePaging } from 'components/hooks/usePaging';
|
||||
|
||||
export function useDataTable(config = {}) {
|
||||
const { initialData, initialQuery, initialPageInfo } = config;
|
||||
const [data, setData] = useState(initialData ?? null);
|
||||
const [query, setQuery] = useState(initialQuery ?? '');
|
||||
const { pageInfo, setPageInfo } = usePaging(initialPageInfo);
|
||||
|
||||
return { data, setData, query, setQuery, pageInfo, setPageInfo };
|
||||
}
|
||||
|
||||
export default useDataTable;
|
||||
9
src/components/hooks/usePaging.js
Normal file
9
src/components/hooks/usePaging.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { useState } from 'react';
|
||||
|
||||
const DEFAULT_PAGE_INFO = { page: 1, pageSize: 10, total: 0 };
|
||||
|
||||
export function usePaging(initialPageInfo) {
|
||||
const [pageInfo, setPageInfo] = useState(initialPageInfo ?? { ...DEFAULT_PAGE_INFO });
|
||||
|
||||
return { pageInfo, setPageInfo };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue