
So, i am trying to make a chat application but i am not recieving the realtime response and not even the error. I am give any permission to my collection to create, read, update and delete.
realTime(callback) {
console.log("Subscribing to real-time updates");
this.unsubscribeFn = this.client.subscribe(
// returns a function
databases.${conf.appwriteDatabaseId}.collections.${conf.appwriteCollectionId}.documents
,
(response) => {
if (response.error) {
console.error("Realtime error:", response.error);
} else {
callback(response);
}
},
);
}
ussage: useEffect(() => { const fetchdata = async () => { try { const response = await dbService.getPosts(); //promise dispatch(intialMsg(response.documents)); // array // console.log(response.documents); // console.log(ans); } catch (error) { console.log("error fetching"); } }; fetchdata();
const handleRealtimeUpdate = (res) => {
console.log("Real-time update received", res);
// Handle different types of events
if (res.events.includes("databases.*.collections.*.documents.*.create")) {
console.log("created");
dispatch(addMsg(res.payload));
} else if (
res.events.includes("databases.*.collections.*.documents.*.delete")
) {
console.log("deleted");
dispatch(rmMsg(res.payload.$id));
} else if (
res.events.includes("databases.*.collections.*.documents.*.update")
) {
console.log("update");
dispatch(updateMsg(res.payload));
}
};
dbService.realTime(handleRealtimeUpdate);
return () => {
dbService.unsubscribe(); // to stop double render
};
}, [dispatch]); // show messages after dom renders

useeffect code
Recommended threads
- Looking for FullStack Developer
I'm looking for FullStack Developer who is passionated about both Frontend and Backend. If you are interested, please DM me. Thanks.
- Asynchronous Function Execution via Func...
Hi everyone, Is there a way to call a function via its function domain URL with async execution set to true?
- Server Error when upserting existing and...
Hello there! Im currently experiencing issues with the not so long ago officially announced upserting funcionality. Im running appwrite 1.7.4 self hosted and no...
