Skip to content

Commit 9ed7fff

Browse files
committed
fix: remove unnecessary hooks #14
1 parent c6a5205 commit 9ed7fff

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-google-adsense",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "Next.js Google AdSense",
55
"main": "dist/index.js",
66
"type": "commonjs",

src/AdLayout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { DetailedHTMLProps } from "react";
1+
import type { DetailedHTMLProps } from "react";
2+
import React from "react";
23

34
export type Layout = "display" | "in-article" | "custom";
45

src/AdUnit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const AdUnit = ({
7878
//? empty object can be passed via .push, see: https://github.com/soranoo/next-google-adsense/issues/6
7979

8080
return (
81-
<div key={pathname.replace(/\//g, "-") + "-" + slotId + "-" + comment.replace(" ", "-")}>
81+
<div key={`${pathname.replace(/\//g, "-")}-${slotId}-${comment.replace(" ", "-")}`}>
8282
{Ad}
8383
</div>
8484
);

src/GoogleAdSense.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import type { ScriptProps } from "next/script";
55

6-
import React, { useEffect } from "react";
6+
import React from "react";
77
import Script from "next/script";
88
import { isPublisherId } from "./utils";
9-
import { usePathname } from "next/navigation";
109

1110
interface GoogleAdSenseProps extends Omit<ScriptProps, "src" | "id"> {
1211
publisherId?: string;
@@ -22,8 +21,6 @@ export const GoogleAdSense = ({
2221
debug = false,
2322
...props
2423
}: GoogleAdSenseProps): JSX.Element | null => {
25-
const pathName = usePathname();
26-
2724
const _publisherId = process.env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID ?? publisherId;
2825

2926
if (!isPublisherId(_publisherId)) {
@@ -38,7 +35,7 @@ export const GoogleAdSense = ({
3835
async={true}
3936
id="next-google-adsense"
4037
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${_publisherId}${
41-
debug ? `google_console=1` : ``
38+
debug ? "google_console=1" : ""
4239
}`}
4340
strategy="afterInteractive"
4441
crossOrigin="anonymous"

0 commit comments

Comments
 (0)