Skip to content

Conversation

@kyleamazza
Copy link
Collaborator

@kyleamazza kyleamazza commented Apr 3, 2025

  • feat: Adds a mutationKey to allow for getting the status of a mutation via useMutationState more easily.

  • fix: Fixes a misspelling for queryOptions.infinite in buildQueryKey

Expected usage:

import { useCreatePost } from '@/src/__generated__/hooks/post';

const MyComponent = () => {
  const createPost = useCreatePost();

  return (
    <button 
      onClick={() => createPost.mutate({ message: 'hello world' })}
    >
      Create Post
    </button>
  );
}

// Elsewhere:
import { useMutationState } from '@tanstack/query';
import { useCreatePost } from '__generated__/hooks/post';

const MyListeningComponent = () => {
  const createPostState = useMutationState({
    filters: { 
      mutationKey: useCreatePost.mutationKey,
      predicate: (mutation) => mutation.state.variables?.message === 'hello world',
    },
  });
 
  return createPostState.state.status === 'pending' 
    ? <Loading /> 
    : <p>Post created!</p>;
};

@kyleamazza kyleamazza marked this pull request as draft April 3, 2025 18:33
@kyleamazza kyleamazza marked this pull request as ready for review April 3, 2025 19:49
@kyleamazza kyleamazza changed the base branch from main to alpha April 3, 2025 23:37
@kyleamazza
Copy link
Collaborator Author

Closed in favor of #15

@kyleamazza kyleamazza closed this Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants