diff --git a/resources/js/hooks/use-server-table.ts b/resources/js/hooks/use-server-table.ts index ed4521b..fa2a07f 100644 --- a/resources/js/hooks/use-server-table.ts +++ b/resources/js/hooks/use-server-table.ts @@ -1,5 +1,5 @@ import { router } from '@inertiajs/react'; -import { useCallback, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import type { PaginationState } from '@/components/data-table'; type UseServerTableOptions = { @@ -18,6 +18,18 @@ export function useServerTable({ const [search, setSearch] = useState(''); const [filterOpen, setFilterOpen] = useState(false); + useEffect(() => { + const params = new URLSearchParams(window.location.search); + if (params.has('search')) { + params.delete('search'); + const cleanUrl = + window.location.pathname + + (params.toString() ? `?${params.toString()}` : ''); + history.replaceState(null, '', cleanUrl); + router.get(route(), {}, { preserveState: true, replace: true }); + } + }, []); + const handlePageChange = useCallback( (page: number) => { router.get(