"use client";

import { SWRConfig } from "swr";
import { ReactNode } from "react";

// SWR fetcher function
export const fetcher = (url: string) => fetch(url).then((res) => res.json());

interface SWRProviderProps {
  children: ReactNode;
}

export function SWRProvider({ children }: SWRProviderProps) {
  return (
    <SWRConfig
      value={{
        fetcher,
        revalidateOnFocus: false,
        revalidateOnReconnect: false,
        shouldRetryOnError: false,
        errorRetryCount: 1,
        dedupingInterval: 2000,
      }}
    >
      {children}
    </SWRConfig>
  );
}
