Skip to content

Instantly share code, notes, and snippets.

@tanat
Last active November 4, 2025 23:17
Show Gist options
  • Select an option

  • Save tanat/61b03011a1e2bb689a83aca10e37ccfc to your computer and use it in GitHub Desktop.

Select an option

Save tanat/61b03011a1e2bb689a83aca10e37ccfc to your computer and use it in GitHub Desktop.
gameApi.ts
import { createApi } from '@reduxjs/toolkit/query/react';
import { baseQuery } from '@shared/api';
import { Contest } from '@shared/types';
export const contestApi = createApi({
reducerPath: 'contestApi',
baseQuery,
tagTypes: ['Contest', 'Leaderboard'],
endpoints: (builder) => ({
// Get contest by ID
getContest: builder.query<Contest, number>({
query: (id) => ({
url: `v2/contests/${id}/`,
method: 'GET',
}),
providesTags: ['Contest'],
}),
// Get leaderboard
getLeaderboard: builder.query<any[], string>({
query: (date) => ({
url: `api/v1/leaderboard/?date=${date}`,
method: 'GET',
}),
providesTags: ['Leaderboard'],
}),
}),
});
export const {
useGetContestQuery,
useGetLeaderboardQuery,
useLazyGetLeaderboardQuery,
} = contestApi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment