Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

742 B
Raw Blame
import { toast } from "@webstudio-is/design-system";
import { useEffect } from "react";
import { $toastErrors } from "../nano-states";

let toastErrorsIndex = 0;

/**
 * To show errors exposed from the canvas | builder
 */
export const useToastErrors = () => {
  useEffect(() => {
    return $toastErrors.subscribe((toastErrors) => {
      for (
        let errorIndex = toastErrorsIndex;
        errorIndex < toastErrors.length;
        errorIndex++
      ) {
        toast.error(toastErrors[errorIndex]);
      }

      toastErrorsIndex = toastErrors.length;
    });
  }, []);
};

export const toastError = (_error: string) => {
  $toastErrors.set([
    ...$toastErrors.get(),
    "Copying has been disabled by the project owner",
  ]);
};