mirror of
https://github.com/lemeow125/React-NotesApp.git
synced 2024-11-16 22:19:27 +08:00
Moved fetch query to own function
This commit is contained in:
parent
a7b556d0dd
commit
d96c26bc1a
2 changed files with 9 additions and 11 deletions
7
src/Components/Api/Api.tsx
Normal file
7
src/Components/Api/Api.tsx
Normal 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;
|
||||
});
|
||||
}
|
|
@ -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}>
|
||||
|
|
Loading…
Reference in a new issue