Skip to content

Commit

Permalink
enforce client only to side step known bug of next ui Input
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncurtisyoga committed Nov 30, 2024
1 parent 9ce0590 commit a8666c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 25 additions & 0 deletions _components/ClientOnly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

import { useState, useEffect, ReactNode, FC } from "react";

interface ClientOnlyProps {
children: ReactNode;
fallback?: ReactNode;
}

const ClientOnly: FC<ClientOnlyProps> = ({ children, fallback = null }) => {
const [hasMounted, setHasMounted] = useState(false);

useEffect(() => {
setHasMounted(true);
}, []);

// Render fallback (e.g., spinner) or nothing while client-only content loads
if (!hasMounted) {
return <>{fallback}</>;
}

return <>{children}</>;
};

export default ClientOnly;
6 changes: 4 additions & 2 deletions _components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Link from "next/link";
import { Link as NextUiLink } from "@nextui-org/react";
import { AudioLines, Instagram, Youtube } from "lucide-react";
import ClientOnly from "@/_components/ClientOnly";
import NewsletterForm from "@/_components/NewsletterForm";
import { instructorEmailAddress } from "@/_lib/constants";

const Footer = () => {
return (
<footer data-testid="footer" className={"border-t py-6 bg-zinc-50"}>
Expand All @@ -15,7 +15,9 @@ const Footer = () => {
>
{/* Newsletter Signup Form */}
<div data-testid="footer-newsletter" className={"flex justify-center"}>
<NewsletterForm />
<ClientOnly>
<NewsletterForm />
</ClientOnly>
</div>

{/* Social Media Links */}
Expand Down

0 comments on commit a8666c7

Please sign in to comment.