neet/refined-itsukara-link

View on GitHub
packages/@neet/vschedule-client/src/components/hooks/useEvents.ts

Summary

Maintainability
A
3 hrs
Test Coverage
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import type { SWRConfiguration } from 'swr';
import useSWR from 'swr';

import { proxyAPI } from '../../api-legacy';
import type { EventsResponse } from '../../types';

export const useEvents = (config?: SWRConfiguration<EventsResponse>) => {
  const { data, error, isValidating } = useSWR<EventsResponse, unknown>(
    '/api/v1.2/events.json',
    proxyAPI.fetchEvents,
    config,
  );

  return { events: data?.data.events, error, loading: isValidating };
};