From f4d152b0e712eaa86050e53fe9b867a6f3fd810d Mon Sep 17 00:00:00 2001
From: Felipe D'Abrantes <felidabrantes@gmail>
Date: Fri, 21 Apr 2023 20:18:14 +0100
Subject: [PATCH] Wait for question to insert before updating page

---
 .../src/components/questions/NewQuestionForm.tsx              | 2 +-
 daily-thought-frontend/src/pages/questions.tsx                | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/daily-thought-frontend/src/components/questions/NewQuestionForm.tsx b/daily-thought-frontend/src/components/questions/NewQuestionForm.tsx
index 2f5118ca..10237766 100644
--- a/daily-thought-frontend/src/components/questions/NewQuestionForm.tsx
+++ b/daily-thought-frontend/src/components/questions/NewQuestionForm.tsx
@@ -3,7 +3,7 @@ import { Dispatch, FC, FormEvent, SetStateAction } from 'react';
 type NewQuestionFormProps = {
   newQuestion: string;
   setNewQuestion: Dispatch<SetStateAction<string>>;
-  onSubmit: () => void;
+  onSubmit: () => Promise<void>;
 };
 
 const NewQuestionForm: FC<NewQuestionFormProps> = ({ newQuestion, setNewQuestion, onSubmit }) => {
diff --git a/daily-thought-frontend/src/pages/questions.tsx b/daily-thought-frontend/src/pages/questions.tsx
index 9e57b67a..bc163a95 100644
--- a/daily-thought-frontend/src/pages/questions.tsx
+++ b/daily-thought-frontend/src/pages/questions.tsx
@@ -24,8 +24,8 @@ const Questions = () => {
     await fetch(endpoint, options);
   };
 
-  const onQuestionSubmit = (): void => {
-    insertNewQuestion(newQuestion);
+  const onQuestionSubmit = async (): Promise<void> => {
+    await insertNewQuestion(newQuestion);
     setRehydrateQuestions(true);
   };
 
-- 
GitLab