diff --git a/src/components/social/compose.tsx b/src/components/social/compose.tsx index c5be526..b25f14d 100644 --- a/src/components/social/compose.tsx +++ b/src/components/social/compose.tsx @@ -2,9 +2,8 @@ import { useCreatePost } from "@/lib/social"; import { useState } from "react"; export default function Compose() { - const mutation = useCreatePost(); - const [text, setText] = useState(""); + const mutation = useCreatePost({ cleanup: () => setText("") }); const handleSubmit = async () => { mutation.mutate({ content: { text, type: "md" } }); diff --git a/src/lib/social.ts b/src/lib/social.ts index 15f3828..7700bc5 100644 --- a/src/lib/social.ts +++ b/src/lib/social.ts @@ -137,13 +137,16 @@ export function useGetPosts(limit: number = 10, order: string = "desc") { }); } -export function useCreatePost() { +export function useCreatePost({ cleanup }: { cleanup?: () => void }) { const { wallet } = useWallet(); return useMutation({ onSuccess: () => { // Invalidate and refetch the "posts" query queryClient.invalidateQueries({ queryKey: ["posts"] }); + if (cleanup) { + cleanup(); + } }, mutationFn: async ({ content }: { content: any }) => { try { diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 60a493e..3b237ef 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -29,6 +29,11 @@ function RootComponent() {
+
+ + view source + +