summaryrefslogtreecommitdiff
path: root/src/apiSlice.ts
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-02-21 19:43:07 -0600
committerMichael Hunteman <michael@huntm.net>2024-02-21 19:43:07 -0600
commit589e53f152d7363074049dfd1bd5a34286ae74d6 (patch)
tree187b98b25f7f3420ad2642171fd7d91a68713211 /src/apiSlice.ts
parent32e0cacde5a468d8982d5c0d1fd7a242820cb60f (diff)
Update example guests.json with RTK query
Diffstat (limited to 'src/apiSlice.ts')
-rw-r--r--src/apiSlice.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/apiSlice.ts b/src/apiSlice.ts
new file mode 100644
index 0000000..6d779ed
--- /dev/null
+++ b/src/apiSlice.ts
@@ -0,0 +1,26 @@
+import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
+
+export const apiSlice = createApi({
+ reducerPath: 'api',
+ baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:3000' }),
+ tagTypes: ['Guests'],
+ endpoints: builder => ({
+ getGuests: builder.query({
+ query: () => '/guests',
+ providesTags: ['Guests']
+ }),
+ updateGuest: builder.mutation({
+ query: guest => ({
+ url: `/guests/${guest.id}`,
+ method: 'PATCH',
+ body: guest,
+ providesTags: ['Guests']
+ })
+ })
+ })
+});
+
+export const {
+ useGetGuestsQuery,
+ useUpdateGuestMutation
+} = apiSlice;