Skip to content

invalidatesTags works even if the request is 422 http status #3514

Answered by EskiMojo14
phoique asked this question in Q&A
Discussion options

You must be logged in to vote

if you provide an array for invalidatesTags, it will invalidate those tags for both successful and unsuccessful requests.

if you only want to invalidate tags for successful requests, you should provide a callback:

testMutation: builder.mutation({
	query: (body) => ({
		url: 'test/services',
		method: 'POST',
		body,
	}),
	invalidatesTags: (result, error, arg) => !error ? ptpApi.invalidatesTags(['testInvalidatesTags']) : [],
	extraOptions: {
		toastSuccessMessageKey: 'testMutation',
		toastErrorMessageKey: 'testMutation',
	},
}),

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@phoique
Comment options

@EskiMojo14
Comment options

@phoique
Comment options

@EskiMojo14
Comment options

Answer selected by phoique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants