Moved fetch query to own function

This commit is contained in:
keannu125 2023-02-25 21:21:23 +08:00
parent a7b556d0dd
commit d96c26bc1a
2 changed files with 9 additions and 11 deletions

View file

@ -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;
});
}

View file

@ -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 (
<div style={styles.note}>