Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Chapter 4) The React useQuery() / useMutation #27

Open
KATT opened this issue Feb 1, 2022 · 1 comment
Open

Chapter 4) The React useQuery() / useMutation #27

KATT opened this issue Feb 1, 2022 · 1 comment
Assignees
Labels
❕ RFC Request for comments - please comment!

Comments

@KATT
Copy link
Member

KATT commented Feb 1, 2022

The React API

Suggestion A) Similar to existing API

const trpc = createReactQueryHooks<AppRouter>()

const {queries, mutations, useQuery, useMutation} = trpc;

/// usage

function MyComponent() {
  // you can CMD+Click `postById` and jump straight to the backend resolver
  const query1 = useQuery([queries.postById, { id: 1 }], { /* react-query opts  */ })

  // Also same query and will be usable, but you lose jump to definition
  const query2 = useQuery(['postById', { id: 1 }], { /* react-query opts  */ })


  const mutation1 = useMutation(mutations.postUpdate); // <-- jump to definition by clicking `postUpdate`
  const mutation2 = useMutation('updatePost');

  // later used as `mutation.mutate(input)` or `mutation.mutateAsync(input)`

}

Suggestion B) Pseudo-call within hook

trpc.useQuery(client.query.postById({ id: 1 }), { /* react-query options */ })

Suggestion C) Skipping the tuple

Related decision

const trpc = createReactQueryHooks<AppRouter>()

const {queries, mutations, useQuery, useMutation} = trpc;

/// usage

function MyComponent() {
  // you can CMD+Click `postById` and jump straight to the backend resolver
  const query1 = useQuery(queries.postById, { 
    input: { id: 1 }, 
    /* [...] other react-query opts */
  }) 

  // Also same query and will be usable, but you lose jump to definition
  const query2 = useQuery('postById', {
    input: { id: 1 },
    /* [...] other react-query opts */
  }) 
}
@KATT KATT added the ❕ RFC Request for comments - please comment! label Feb 1, 2022
@KATT KATT moved this to Done in Roadmap and priorities Apr 11, 2022
@KATT KATT self-assigned this Apr 11, 2022
@KATT KATT moved this from Done to In Review in Roadmap and priorities Apr 11, 2022
@KATT
Copy link
Member Author

KATT commented Apr 12, 2022

Suggestion A won the vote

@KATT KATT closed this as completed Apr 12, 2022
Repository owner moved this from In Review to Done in Roadmap and priorities Apr 12, 2022
@KATT KATT reopened this Apr 12, 2022
@jlalmes jlalmes moved this from ✅ Done to 👀 In Review in Roadmap and priorities Apr 12, 2022
@KATT KATT moved this from 👀 In Review to 🚧 In Progress in Roadmap and priorities Jun 19, 2022
@KATT KATT moved this from 🚧 In Progress to ✅ Done in Roadmap and priorities Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❕ RFC Request for comments - please comment!
Projects
Archived in project
Development

No branches or pull requests

1 participant