We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7d00ad0 commit 39179f1Copy full SHA for 39179f1
1 file changed
app/src/components/PostForm.tsx
@@ -1,9 +1,11 @@
1
import type { ReactElement } from "react";
2
import { useState } from "react";
3
+import { useQueryClient } from "@tanstack/react-query";
4
5
import createPost from "../api/createPost";
6
7
export default function PostForm(): ReactElement {
8
+ const queryClient = useQueryClient();
9
const [form, setForm] = useState({
10
head: "",
11
body: "",
@@ -15,7 +17,8 @@ export default function PostForm(): ReactElement {
15
17
}
16
18
createPost(form)
19
.then(() => {
- window.location.reload();
20
+ setForm({ head: "", body: "" }); // Reset form
21
+ queryClient.invalidateQueries({ queryKey: ["posts"] }); // Trigger posts refetch
22
})
23
.catch((error) => {
24
console.error(error); // eslint-disable-line no-console
0 commit comments