Is it possible to updateQueryData on a new nonexistent query - RTK Query? #2734
Answered
by
phryneas
LoyalPotato
asked this question in
Q&A
-
I've an api created with RTK Query, and I have a create endpoint that pessimistically updates other queries: create: builder.mutation<
{ id: string },
Req
>({
query: (req) => ({
url: "",
method: "POST",
body: req,
}),
async onQueryStarted(req, { dispatch, queryFulfilled }) {
try {
const {
data: { id },
} = await queryFulfilled;
dispatch(
apiSvc.util.updateQueryData(
"getFoos",
{ specialId: req.specialId },
(draft) => {
draft.unshift({
...req,
id
});
}
)
);
dispatch(
apiSvc.util.updateQueryData(
"getSingleFoo",
{ specialId: req.specialId, otherSpecialId: req.otherSpecialId },
(draft) => {
Object.assign(draft, {
...req,
id
});
}
)
);
} catch (e) {
console.error(e);
}
},
}), But updating the Is it possible to do this? If so how? (I had asked this in stackoverflow as well) |
Beta Was this translation helpful? Give feedback.
Answered by
phryneas
Sep 28, 2022
Replies: 1 comment
-
See #1720 - we are currently evaluating an |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
LoyalPotato
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See #1720 - we are currently evaluating an
upsertQueryData
functionality, but the latest alpha still has a bug preventing it from being used.