diff options
| author | realtradam <[email protected]> | 2024-07-27 20:20:29 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-07-27 20:20:29 -0400 |
| commit | c366e70e95156d2637f82116312770e12a9aad32 (patch) | |
| tree | f1724ea1945f492e73cc1e98606d86c61c98f0be /frontend/src/pages | |
| parent | 9148f894e02bf43775e18fc873a9deab5c36220c (diff) | |
| download | spring-blog-c366e70e95156d2637f82116312770e12a9aad32.tar.gz spring-blog-c366e70e95156d2637f82116312770e12a9aad32.zip | |
implement delete functionality
Diffstat (limited to 'frontend/src/pages')
| -rw-r--r-- | frontend/src/pages/Home.tsx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index bada22d..71683e7 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, FormEvent } from "react"; +import { useState, useEffect, useCallback, FormEvent } from "react"; type article = { id: number; @@ -31,7 +31,7 @@ export default function Home({ }; const response = await fetch( - `${import.meta.env.VITE_API_TITLE}/api/v1/article/delete/${target.id.value}`, + `${import.meta.env.VITE_API_TITLE}/api/v1/articles/delete/${target.id.value}`, { credentials: "include", method: "get", @@ -41,10 +41,12 @@ export default function Home({ console.log(response); alert("check console for error"); } + else { + fetchArticles(); + } }; - // pull data when new search is given - useEffect(() => { + const fetchArticles = useCallback(() => { let url; if (articleSearch.value === null) { //alert("not searched"); @@ -65,6 +67,9 @@ export default function Home({ .then((response) => setArticles(response)); }, [articleSearch.value]); + // pull data when new search is given + useEffect(() => { fetchArticles(); } , [articleSearch.value, fetchArticles]); + // when new data is pulled update the articles shown useEffect(() => { setAllArticles( |
