Files
co-lite/solvway-admin-portal/app/lib/hooks/useResetPageOnCompany.ts
T

15 lines
516 B
TypeScript

"use client";
import { useEffect, useRef } from "react";
import { useCompanyScope } from "@/app/lib/CompanyScope";
/** A different company is a different list: go back to page 1 when the picker changes (not on first render). */
export function useResetPageOnCompany(setPage: (p: number) => void) {
const { companyId } = useCompanyScope();
const last = useRef(companyId);
useEffect(() => {
if (last.current === companyId) return;
last.current = companyId;
setPage(1);
}, [companyId, setPage]);
}