Rank 2: Process
and after that it reloads the page
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 2: Process
and after that it reloads the page
i don't see the print statement 🧐
also it seems like the page is refreshing? 🧐
Rank 2: Process
yes bcz after printing the statement page relaods itself
why?
Rank 2: Process
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();
}
};
Rank 2: Process
here is the code
why are you adding the reload?
Rank 2: Process
to render the list after newly add item or deleting item
i don't think that's the right approach...
Rank 2: Process
I know but in the useEffect function if I gave the any payload or leave it empty it calls the function infinitely
Rank 2: Process
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?
Rank 2: Process
see this video
Rank 2: Process
Rank 2: Process
if I gave any payload then its happening
what do you mean?
Rank 2: Process
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]);
Rank 2: Process
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?
Rank 2: Process
Yes I know but I found a solution using useReducer
Rank 2: Process
Its work on the submit function and load function correctly
Rank 2: Process
Now I'm implementing it on the deleting function
Rank 2: Process
Thanks @Steven to help me. Now it is working perfectly.
[SOLVED] Not deleting at first