Search code examples
rtk-query

Get meta after running mutation


After running the mutation, I want to get the meta returned by baseQuery. I printed the result, but there is no meta in it. Is there any way to get the meta here?

const [addPost, { isLoading }] = useAddPostMutation();
// ...
const handleAddPost = async () => {
  const result = await addPost(post);
  console.log(result);
  // => { data: {...} }
  // but required this: { data: {...}, meta: { ... } }
}

Solution

  • You can only access meta in transformResponse and make it part of data - after that it is thrown away.