and after that it reloads the page
i don't see the print statement π§
also it seems like the page is refreshing? π§
yes bcz after printing the statement page relaods itself
why?
const deleteTodoHandler = async (id) => {
try {
db.deleteDocument(
import.meta.env.VITE_APPWRITE_DATABASE_ID,
import.meta.env.VITE_APPWRITE_COLLECTION_ID,
id
);
console.log('deleted');
window.location.reload();
} catch (err) {
console.log(err);
window.location.reload();
}
};
here is the code
why are you adding the reload?
to render the list after newly add item or deleting item
i don't think that's the right approach...
I know but in the useEffect function if I gave the any payload or leave it empty it calls the function infinitely
useEffect(() => {
const loadData = async () => {
setLoader(true);
try {
const getTodos = await db.listDocuments(
import.meta.env.VITE_APPWRITE_DATABASE_ID,
import.meta.env.VITE_APPWRITE_COLLECTION_ID
);
setTodos(getTodos.documents);
} catch (err) {
console.log(err);
}
};
loadData();
setLoader(false);
}, []);
how do you know it calls the function infinitely?
see this video
if I gave any payload then its happening
what do you mean?
useEffect(() => {
const loadData = async () => {
setLoader(true);
try {
const getTodos = await db.listDocuments(
import.meta.env.VITE_APPWRITE_DATABASE_ID,
import.meta.env.VITE_APPWRITE_COLLECTION_ID
);
setTodos(getTodos.documents);
} catch (err) {
console.log(err);
}
};
loadData();
setLoader(false);
}, [todos]);
I mean this code
yes, that's causing the infinite loop. That todos
at the bottom means "run this whenever todos
changes" and you're changing todo in the loadData
function. Does that make sense?
Yes I know but I found a solution using useReducer
Its work on the submit function and load function correctly
Now I'm implementing it on the deleting function
Thanks @Steven to help me. Now it is working perfectly.
[SOLVED] Not deleting at first
Recommended threads
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...