Switch back to useEffect in FlaggableElement to ensure valid labels are present

This commit is contained in:
Keith Stevens
2023-01-16 14:44:38 +09:00
parent 51bbec0c49
commit c4af8bba1e
+9 -7
View File
@@ -22,7 +22,7 @@ import {
} from "@chakra-ui/react";
import { QuestionMarkCircleIcon } from "@heroicons/react/20/solid";
import clsx from "clsx";
import { useReducer } from "react";
import { useEffect, useReducer } from "react";
import { FiAlertCircle } from "react-icons/fi";
import { get, post } from "src/lib/api";
import { Message } from "src/types/Conversation";
@@ -100,12 +100,14 @@ export const FlaggableElement = (props: FlaggableElementProps) => {
);
const [isEditing, setIsEditing] = useBoolean();
useSWR("/api/valid_labels", get, {
onSuccess: (data) => {
const { valid_labels } = data;
updateReport({ type: "load_labels", labels: valid_labels });
},
});
const { data, isLoading } = useSWR("/api/valid_labels", get);
useEffect(() => {
if (isLoading) {
return;
}
const { valid_labels } = data;
updateReport({ type: "load_labels", labels: valid_labels });
}, [data, isLoading]);
const { trigger } = useSWRMutation("/api/set_label", post, {
onSuccess: () => {