12 lines · 470 BRaw
| 1 | import { repoLink, type LastChanges } from "@refs/backend/contract"; |
| 2 | import { useEffect } from "react"; |
| 3 | import { useFetcher } from "react-router"; |
| 4 | |
| 5 | export function useLastChanges(repo: string, ref: string | null, path: readonly string[]): LastChanges | undefined { |
| 6 | const fetcher = useFetcher<LastChanges>(); |
| 7 | const url = ref ? repoLink(repo, "last-commits", ref, path) : null; |
| 8 | useEffect(() => { |
| 9 | if (url) fetcher.load(url); |
| 10 | }, [url]); |
| 11 | return fetcher.data; |
| 12 | } |