mirror of
https://github.com/lemeow125/React-NotesApp.git
synced 2024-11-17 06:29:28 +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 { Button } from "@mui/material";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { GetNotes } from "../Api/Api";
|
||||||
|
|
||||||
export default function Notes() {
|
export default function Notes() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const {
|
const { data: notes, isLoading, error } = useQuery("notes", GetNotes);
|
||||||
data: notes,
|
|
||||||
isLoading,
|
|
||||||
error,
|
|
||||||
} = useQuery("notes", () => {
|
|
||||||
return fetch("http://localhost:8000/api/v1/notes/").then((res) => {
|
|
||||||
const result = res.json();
|
|
||||||
console.log();
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div style={styles.note}>
|
<div style={styles.note}>
|
||||||
|
|
Loading…
Reference in a new issue