Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vs-kishu opened this issue Nov 5, 2023 · 2 comments

Comments

@Vs-kishu
Copy link

Vs-kishu commented Nov 5, 2023

    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 Vs-kishu changed the title user is sending update request even there is no change in any fields Nov 5, 2023
@Vs-kishu
Copy link
Author

Vs-kishu commented Nov 7, 2023

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
Copy link

hmongdev commented Nov 7, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants