Closed drMonro closed 1 year ago
Can you reproduce it in https://www.typescriptlang.org/play ? You can import libraries there.
I think you misunderstand the usage.
https://github.com/jotaijs/jotai-trpc/blob/9751009852034759df5cd22aa915f2be039964dc/src/createTRPCJotai.ts#L142-L148
The first argument is optional getClient
. So, you don't need to specify anything.
👉 https://tsplay.dev/Wzx4LN
and setting 'cartId' in Atoms layer?
Does that mean you want to set the atom value based on the mutation output?? You would be able to create a new atom then.
I just tried to make construction like in 'atomWithQuery', where I set parameters which is required for GET response right in Atom layer (not inside component)
How can I do the same but with 'atomWithMutation'?
Now i had to set 'cartId' when i call mutation in component, though i got 'cartAtom' data in Jotaii layer
Ah, I see. It wasn't a TS issue, but it's more like Jotai usage question.
I think you can create another action atom.
export const cartAtom = atom({ id: '', items: [] })
const deleteFromCartAtom = api.cart.del.atomWithMutation()
export const deleteCurrentFromCurtAtom = atom(null, async (get, set) => {
const cart = get(cartAtom)
const output = await set(deleteFromCartAtom, {
cartId: cart.id,
})
console.log(output)
})
Oh! Ok! Thank you I'll try this approach
So, with that approach i can't set part of arguments on Component layer and another part on Jotai layer - and i need to create 'offerIdAtom', right?
I'm not 100% following, but if it's about how to use jotai apart from jotai-trpc, it sounds about right.
How to make custom mutation? I just want to call mutation with signing only 'offerId' and setting 'cartId' in Atoms layer? Now i got TS error
How to fix? Or i missing something? Thx