MCPcopy Create free account
hub / github.com/dailydotdev/apps / useUpdatePost

Function useUpdatePost

packages/shared/src/hooks/useUpdatePost.ts:11–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9};
10
11export default function useUpdatePost(): UseBookmarkPostRet {
12 const client = useQueryClient();
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,
40 };
41}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected