adrianhajdin / social_media_app

Build a modern social app with a stunning UI with a native mobile feel, a special tech stack, an infinite scroll feature, and amazing performance using React JS, Appwrite, TypeScript, and more.
https://jsmastery.pro
1.07k stars 322 forks source link

user is sending update post request even there is no change in any fields #9

Open Vs-kishu opened 8 months ago

Vs-kishu commented 8 months ago

    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('/');
  };
Vs-kishu commented 8 months ago

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

hmongdev commented 8 months ago

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?