Skip to content

Commit

Permalink
fix: server-only cannot be imported from a Client Component module. I…
Browse files Browse the repository at this point in the history
…t should only be used from a Server Component.
  • Loading branch information
gabriel-logan committed Jun 23, 2024
1 parent 2bea40a commit 8184d90
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 66 deletions.
75 changes: 75 additions & 0 deletions docs/src/app/[locale]/news/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use client";

import { useEffect, useState } from "react";

import { AddBanner } from "@/components/Adsense";

export default function ClientNewsPage() {
const GOOGLE_ADSENSE_CLIENT_ID =
process.env.NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID ?? "";

const SlotAd1AndAd2 = "9630566447";
const SlotAd3 = "8700628151";
const SlotAd4 = "3500719479";
const SlotAd5AndAd6 = "7092033017";

const [isClient, setIsClient] = useState(false);

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

return (
<>
{isClient && (
<>
<div id="news-page">
<div className="div-ad div-ad1">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd1AndAd2}
/>
</div>

<div className="div-ad div-ad2">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd1AndAd2}
/>
</div>

<div className="div-ad div-ad3">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd3}
AdFormat="fluid"
/>
</div>

<div className="div-ad div-ad4">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd4}
AdFormat="autorelaxed"
/>
</div>

<div className="div-ad div-ad5">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd5AndAd6}
/>
</div>

<div className="div-ad div-ad6">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd5AndAd6}
/>
</div>
</div>
</>
)}
</>
);
}
72 changes: 6 additions & 66 deletions docs/src/app/[locale]/news/page.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,17 @@
"use client";

import "@/css/news.css";
import { useEffect, useState } from "react";
import { setStaticParamsLocale } from "next-international/server";

import { AddBanner } from "@/components/Adsense";
import MainBg from "@/components/MainBg";
import { LocaleParams } from "@/types/Params";

export default function NewsPage() {
const GOOGLE_ADSENSE_CLIENT_ID =
process.env.NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID ?? "";

const SlotAd1AndAd2 = "9630566447";
const SlotAd3 = "8700628151";
const SlotAd4 = "3500719479";
const SlotAd5AndAd6 = "7092033017";
import ClientNewsPage from "./client";

const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
}, []);
export default function NewsPage({ params: { locale } }: LocaleParams) {
setStaticParamsLocale(locale);

return (
<MainBg>
{isClient && (
<>
<div id="news-page">
<div className="div-ad div-ad1">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd1AndAd2}
/>
</div>

<div className="div-ad div-ad2">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd1AndAd2}
/>
</div>

<div className="div-ad div-ad3">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd3}
AdFormat="fluid"
/>
</div>

<div className="div-ad div-ad4">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd4}
AdFormat="autorelaxed"
/>
</div>

<div className="div-ad div-ad5">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd5AndAd6}
/>
</div>

<div className="div-ad div-ad6">
<AddBanner
AdClient={GOOGLE_ADSENSE_CLIENT_ID}
AdSlot={SlotAd5AndAd6}
/>
</div>
</div>
</>
)}
<ClientNewsPage />
</MainBg>
);
}

0 comments on commit 8184d90

Please sign in to comment.