From d96c26bc1a474e20222a6ba59150592ac62e8bf2 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sat, 25 Feb 2023 21:21:23 +0800 Subject: [PATCH] Moved fetch query to own function --- src/Components/Api/Api.tsx | 7 +++++++ src/Components/Notes/Notes.tsx | 13 ++----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 src/Components/Api/Api.tsx diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx new file mode 100644 index 0000000..947730c --- /dev/null +++ b/src/Components/Api/Api.tsx @@ -0,0 +1,7 @@ +export function GetNotes() { + return fetch("http://localhost:8000/api/v1/notes/").then((res) => { + const result = res.json(); + console.log(); + return result; + }); +} diff --git a/src/Components/Notes/Notes.tsx b/src/Components/Notes/Notes.tsx index d877107..3ef5c35 100644 --- a/src/Components/Notes/Notes.tsx +++ b/src/Components/Notes/Notes.tsx @@ -6,20 +6,11 @@ import Note from "../Note/Note"; import { Button } from "@mui/material"; import axios from "axios"; import { useQuery } from "react-query"; +import { GetNotes } from "../Api/Api"; export default function Notes() { const navigate = useNavigate(); - const { - data: notes, - isLoading, - error, - } = useQuery("notes", () => { - return fetch("http://localhost:8000/api/v1/notes/").then((res) => { - const result = res.json(); - console.log(); - return result; - }); - }); + const { data: notes, isLoading, error } = useQuery("notes", GetNotes); if (error) { return (