Skip to content

Commit

Permalink
chore: use abortController
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne committed Oct 14, 2024
1 parent 26f70d4 commit f5c862c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/hooks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export const useHomeTimeline = (): {
const [error, setError] = useState<string>("loading...");

useEffect(() => {
const abortController = new AbortController();
const fetchTimeline = async () => {
try {
const timelineRes = await fetch("http://localhost:3000/timeline/home", {
headers: {
authorization: `Bearer ${localStorage.getItem("authToken")}`,
},
signal: abortController.signal,
});
if (!timelineRes.ok) {
const errorJSON = await timelineRes.json();
Expand All @@ -48,6 +50,9 @@ export const useHomeTimeline = (): {
}
};
fetchTimeline();
return () => {
abortController.abort();
};
}, []);

return {
Expand Down

0 comments on commit f5c862c

Please sign in to comment.