fix /explore recursion due to useEffect (#164)

* fix: /explore recursion

---------

Co-authored-by: Stan Girard <girard.stanislas@gmail.com>
This commit is contained in:
!MAD! 2023-05-26 14:57:29 +05:30 committed by GitHub
parent f69c64ead1
commit 0c6d7fded2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,31 +18,30 @@ export default function ExplorePage() {
redirect("/login");
}
const fetchDocuments = async () => {
setIsPending(true);
try {
console.log(
`Fetching documents from ${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`
);
const response = await axios.get<{ documents: Document[] }>(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`,
{
headers: {
Authorization: `Bearer ${session.access_token}`,
},
}
);
setDocuments(response.data.documents);
} catch (error) {
console.error("Error fetching documents", error);
setDocuments([]);
}
setIsPending(false);
};
useEffect(() => {
const fetchDocuments = async () => {
setIsPending(true);
try {
console.log(
`Fetching documents from ${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`
);
const response = await axios.get<{ documents: Document[] }>(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`,
{
headers: {
Authorization: `Bearer ${session.access_token}`,
},
}
);
setDocuments(response.data.documents);
} catch (error) {
console.error("Error fetching documents", error);
setDocuments([]);
}
setIsPending(false);
};
fetchDocuments();
}, [fetchDocuments]);
}, []);
return (
<main>