-
I have the following code: const roomSlice = mainApi.injectEndpoints({
tags: ['rooms'],
endpoints: (builder) => ({
getMany: builder.query({
query: () => ({
url: `/rooms`,
providesTags: ['rooms'],
}),
}),
createOne: builder.mutation({
query: (payload) => ({
url: '/rooms',
method: 'POST',
body: payload,
invalidatesTags: ['rooms'],
}),
}),
}),
}) I noticed that the tags aren't doing anything, I create a room and then I look at the table of the rooms on my webpage, and it shows out nothing is updated until I refresh the page. Is it allowed to have tags inside injectEndpoints? if not, what are the alternatives? I have a big back-end API, and I need to split the code into multiple files somehow. I found another question similar to this one, but it doesn't talk about |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
you got the nesting wrong and there is no plain "tags" option const roomSlice = mainApi
+.enhanceEndpoints({
+ addTagTypes: ['rooms'],
+})
.injectEndpoints({
- tags: ['rooms'],
endpoints: (builder) => ({
getMany: builder.query({
query: () => ({
url: `/rooms`,
- providesTags: ['rooms'],
}),
+ providesTags: ['rooms'],
}),
createOne: builder.mutation({
query: (payload) => ({
url: '/rooms',
method: 'POST',
body: payload,
- invalidatesTags: ['rooms'],
}),
+ invalidatesTags: ['rooms'],
}),
}),
}) |
Beta Was this translation helpful? Give feedback.
you got the nesting wrong and there is no plain "tags" option