import { cn } from "../helpers"; import { CommentFormSubmitError } from "../errors"; type CommentFormErrorsProps = { error: Error | CommentFormSubmitError; className?: string; }; export function CommentFormErrors({ error, className, }: CommentFormErrorsProps) { return (
{isCommentFormSubmitError(error) ? error.render() : error.message}
); } /** * Check if an error is typeof CommentFormSubmitError, * Use duck typing to avoid CommentFormSubmitError reference issue introduced by bundling */ function isCommentFormSubmitError( error: Error, ): error is CommentFormSubmitError { return ( error instanceof CommentFormSubmitError || ("render" in error && typeof error.render === "function") ); }