🐛 Clear session store when leaving new page (#871)

This commit is contained in:
Luke Vella 2023-09-18 16:06:13 +01:00 committed by GitHub
parent c89a3b939c
commit 2c3602cdfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ import { useRouter } from "next/router";
import React from "react";
import { useForm } from "react-hook-form";
import useFormPersist from "react-hook-form-persist";
import { useUnmount } from "react-use";
import { PollSettingsForm } from "@/components/forms/poll-settings";
import { Trans } from "@/components/trans";
@ -51,11 +52,13 @@ export const CreatePoll: React.FunctionComponent = () => {
},
});
useFormPersist("new-poll", {
const { clear } = useFormPersist("new-poll", {
watch: form.watch,
setValue: form.setValue,
});
useUnmount(clear);
const posthog = usePostHog();
const queryClient = trpc.useContext();
const createPoll = trpc.polls.create.useMutation();
@ -90,7 +93,7 @@ export const CreatePoll: React.FunctionComponent = () => {
optionsView: formData?.view,
});
queryClient.polls.list.invalidate();
router.replace(`/poll/${res.id}`);
router.push(`/poll/${res.id}`);
},
},
);