@dypai-ai/client-sdk - v1.12.0
    Preparing search index...

    Function useAction

    • Hook for mutations (POST, PUT, PATCH, DELETE) to DYPAI endpoints.

      Type Parameters

      • TBody = any
      • TResponse = any

      Parameters

      Returns UseMutationReturn<TBody, TResponse>

      function CreateProduct() {
      const { mutate, isLoading } = useAction('create_product');

      const handleSubmit = async (formData) => {
      const { data, error } = await mutate(formData);
      if (error) alert(error.message);
      };
      }
      // With callbacks and PUT method
      const { mutate: updateTask } = useAction('update_task', {
      method: 'PUT',
      onSuccess: () => refetchTasks(),
      onError: (err) => toast.error(err.message),
      });

      await updateTask({ id: taskId, done: true });
      // Delete
      const { mutate: deleteItem } = useAction('delete_item', { method: 'DELETE' });
      await deleteItem({ id: itemId }); // body sent as params for DELETE