Repository navigation
Conversation
|
π Previously deployed to Railway in the trpc-sse-and-websockets project. Environment has been deleted. |
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
| mutationFn: async (input) => { | ||
| setDataOverride(null); | ||
| const result = await client.mutation( | ||
| ...getClientArgs([path, { input }], opts), | ||
| ); | ||
|
|
||
| if (!isAsyncIterable(result)) { | ||
| return result; | ||
| } | ||
|
|
||
| // `mutateAsync()` returns an async iterable | ||
| async function* iterable() { | ||
| setDataOverride([]); | ||
| for await (const value of result as AsyncIterable<unknown>) { | ||
| setDataOverride((prev) => { | ||
| const next = [...(prev ?? []), value]; | ||
| return next; | ||
| }); | ||
| yield value; | ||
| } | ||
| } | ||
|
|
||
| return iterable(); |
There was a problem hiding this comment.
cc @TkDodo π
is there a way for me to make the mutation stay as pending but still have mutateAsync return the result?
tl;dr
const mutation = trpc.iterable.useMutation()
mutation.data // <--- should be an array that gets updated
mutation.isPending // should probably be true until we have finished receiving all results
// [...]
await mutation.mutateAsync(); // <--- should return an `AsyncIterable`I'm not sure how to access the MutationObserver within the function here
There was a problem hiding this comment.
I don't think so. pending state is defined as "we have no data".
I'm not sure how to access the MutationObserver within the function here
It's not exposed. You would probably have to roll your own useMutation. If you look at the code, it doesn't do that much: Basically create an observer, subscribe to it in useSyncExternalStore and return the result ...
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #5846
π― Changes
Not done, need feedback
β Checklist