mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 02:21:09 +10:00
Implement space member search (#731)
* Hide pagination buttons if there is nothing to paginate * Create reusable hook for search and pagination
This commit is contained in:
17
apps/client/src/hooks/use-paginate-and-search.tsx
Normal file
17
apps/client/src/hooks/use-paginate-and-search.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import { useState, useRef, useCallback } from "react";
|
||||
|
||||
export function usePaginateAndSearch(initialQuery: string = "") {
|
||||
const [search, setSearch] = useState(initialQuery);
|
||||
const [page, setPage] = useState(1);
|
||||
const prevSearchRef = useRef(search);
|
||||
|
||||
const handleSearch = useCallback((newQuery: string) => {
|
||||
if (prevSearchRef.current !== newQuery) {
|
||||
prevSearchRef.current = newQuery;
|
||||
setSearch(newQuery);
|
||||
setPage(1);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { search, page, setPage, handleSearch };
|
||||
}
|
||||
Reference in New Issue
Block a user