
const submit = async (data) => { if (post) { const file = data.image[0] ? await appwriteService.uploadFile(data.image[0]) : null;
TypeScript
if (file) {
appwriteService.deleteFile(post.featuredImage);
}
const dbPost = await appwriteService.updatePost(post.$id, {
...data,
featuredImage: file ? file.$id : undefined,
});
if (dbPost) {
navigate(`/post/${dbPost.$id}`);
}
} else {
const file = await appwriteService.uploadFile(data.image[0]);
if (file) {
const fileId = file.$id;
data.featuredImage = fileId;
const dbPost = await appwriteService.createPost({ ...data, userId: userData.$id });
if (dbPost) {
navigate(`/post/${dbPost.$id}`);
}
}
}
};
TL;DR
Error in code due to trying to access property $id of undefined post. Need to ensure post is not undefined before accessing properties.Recommended threads
- Appwrite stopped working, I can't authen...
I'm having an issue with Appwrite. It was working fine just a while ago, but suddenly it stopped working for me and can't authenticate accounts. I even went bac...
- Set succes/failure url in console
Hi guys, I want to set up a succes and failure url for my OAuth2 provider Google. But I don't see any options for this? Is it not possible to do so? Beside th...
- Fail to receive the verification email a...
I added my email address to prevent it from showing "appwrite," but now I'm not receiving emails for verification or password resets. The function appears to be...
