This repository was archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
This repository was archived by the owner on Dec 19, 2022. It is now read-only.
Chapter 4) The React useQuery() / useMutation #27
Copy link
Copy link
Open
Labels
❕ RFCRequest for comments - please comment!Request for comments - please comment!
Description
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
- Revive [RFC]
useQuery()API alternative trpc#1058 - Add new
inputargument onto the react-query options- If optional, keep optional, if required, require to pass opts
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 */
})
}Metadata
Metadata
Assignees
Labels
❕ RFCRequest for comments - please comment!Request for comments - please comment!
Type
Projects
Status
✅ Done