(props: UpdateData)
| 13 | |
| 14 | const updatePost = |
| 15 | (props: UpdateData): MutateFunc<UpdateData> => |
| 16 | async () => { |
| 17 | const postQueryKey = getPostByIdKey(props.id); |
| 18 | await client.cancelQueries({ queryKey: postQueryKey }); |
| 19 | const oldPost = client.getQueryData<PostData>(postQueryKey); |
| 20 | |
| 21 | if (!oldPost) { |
| 22 | // nothing in cache so we skip any update |
| 23 | |
| 24 | return () => undefined; |
| 25 | } |
| 26 | |
| 27 | client.setQueryData<PostData>(postQueryKey, { |
| 28 | post: { |
| 29 | ...oldPost.post, |
| 30 | ...props.update, |
| 31 | }, |
| 32 | }); |
| 33 | return () => { |
| 34 | client.setQueryData<PostData>(postQueryKey, oldPost); |
| 35 | }; |
| 36 | }; |
| 37 | |
| 38 | return { |
| 39 | updatePost, |
no test coverage detected