social_media_app
social_media_app copied to clipboard
user is sending update post request even there is no change in any fields
if (post && action === 'Update') {
const updatedPost = await updatePost({
...value,
postId: post.$id,
imageId: post.imageId,
imageUrl: post.imageUrl,
});
if (!updatedPost) {
return toast({ title: 'please try again' });
}
return navigate(`/posts/${post.$id}`);
}
const newPost = await createPost({ ...value, userId: user.id });
if (!newPost) {
toast({
title: `${action} post failed. Please try again.`,
});
}
navigate('/');
};
look at My function I am doing same thing
useEffect(() => { if (form.formState.isDirty) { setFileChanged(true); } else { setFileChanged(false); } }, [form.formState.isDirty]);
Using this use Effect we can disabled the update post button so that user cannot click the update button for the API request even he/she not updated any field
look at My function I am doing same thing
useEffect(() => { if (form.formState.isDirty) { setFileChanged(true); } else { setFileChanged(false); } }, [form.formState.isDirty]);
Using this use Effect we can disabled the update post button so that user cannot click the update button for the API request even he/she not updated any field
What does your form look like?