korgko
korgko
TTCTheo's Typesafe Cult
Created by kalufankar on 5/12/2023 in #questions
tRPC + AppRouter without reactQuery
// client/trpc.ts
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

export const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: SERVER_URL,
}),
],
});
// client/trpc.ts
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

export const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: SERVER_URL,
}),
],
});
// client/someFileYouWantToCall.ts
import { trpc } from './trpc'

const greeting = await trpc.getGreeting.query({name: "Korg"});
const createdUser = await trpc.userCreate.mutate({ name: 'Korg' });
// client/someFileYouWantToCall.ts
import { trpc } from './trpc'

const greeting = await trpc.getGreeting.query({name: "Korg"});
const createdUser = await trpc.userCreate.mutate({ name: 'Korg' });
You can read more about it here: https://trpc.io/docs/quickstart
2 replies
TTCTheo's Typesafe Cult
Created by Ruben on 5/13/2023 in #questions
Creating an update mutation with tRPC
Hey! What you're trying to do is to call the useMutation hook itself from inside of a function, and inside your submit function call the mutate property in order to execute your mutation. Here is an example of how it should look like:
const ExampleComponent = ({myId}) => {
const [quantity, setQuantity] = useState(0);
const updateBeerQuantities = api.beer.updateQuantityById.useMutation();

const submitQuantity = (event: React.FormEvent<HTMLInputElement>) => {
event.preventDefault();
updateBeerQuantities.mutate({
id: myId,
quantity: quantity,
});
};

return (
<div>
<button onClick={submitQuantity}>Send mutation</button>
</div>
)
}
const ExampleComponent = ({myId}) => {
const [quantity, setQuantity] = useState(0);
const updateBeerQuantities = api.beer.updateQuantityById.useMutation();

const submitQuantity = (event: React.FormEvent<HTMLInputElement>) => {
event.preventDefault();
updateBeerQuantities.mutate({
id: myId,
quantity: quantity,
});
};

return (
<div>
<button onClick={submitQuantity}>Send mutation</button>
</div>
)
}
2 replies
TTCTheo's Typesafe Cult
Created by 低级黑小明👑 on 5/13/2023 in #questions
variable initialized useState as true but the state is false
if postWithUser is a prop or some outer state that you pass down it could be possible that on the initial render it's value is being set to false and later on changes to true, therefor when your initial useState value is set it will be set to false but hasReaction will be equal to true
5 replies
TTCTheo's Typesafe Cult
Created by Morraez on 5/13/2023 in #questions
T3 for a chat app
You can take a look at this example that uses soketi for sockets that might help you. https://github.com/pingdotgg/zapdos
17 replies