Skip to content

Commit

Permalink
examples: convert @next/third-parties examples from JS to TS (#73602)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change



Closes NEXT-
Fixes #

-->

### What?
- `with-google-maps-embed` example
- `with-google-tag-manager` example
- `with-youtube-embed` example

### Why?
The examples are written in JavaScript.

### How?
Converted JavaScript examples to TypeScript.

---------

Co-authored-by: samcx <[email protected]>
  • Loading branch information
suu3 and samcx authored Dec 17, 2024
1 parent fd0028e commit 6a609fa
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/with-google-maps-embed/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Example app using Google Maps Embed

This example shows how to embed a Google Maps Embed using `@next/third-parties`.
This example shows how to embed a Google Maps Embed using [`@next/third-parties`](https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries).

## Deploy your own

Expand Down
7 changes: 0 additions & 7 deletions examples/with-google-maps-embed/app/layout.js

This file was deleted.

18 changes: 18 additions & 0 deletions examples/with-google-maps-embed/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "With Google Maps Embed",
description: "Next.js example with Google Maps Embed.",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
File renamed without changes.
11 changes: 8 additions & 3 deletions examples/with-google-maps-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"start": "next start"
},
"dependencies": {
"next": "latest",
"@next/third-parties": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"next": "latest",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/react": "^19.0.1",
"typescript": "^5.7.2"
}
}
24 changes: 24 additions & 0 deletions examples/with-google-maps-embed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion examples/with-google-tag-manager/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Example app using Google Tag Manager

This example shows how to include Google Tag Manager in a Next.js application using `@next/third-parties`. The GTM container is instantiated in `layout.js` and the `sendGTMEvent` function is fired in the `EventButton` client component.
This example shows how to include Google Tag Manager in a Next.js application using [`@next/third-parties`](https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries). The GTM container is instantiated in `layout.tsx` and the `sendGTMEvent` function is fired in the `EventButton` client component.

## Deploy your own

Expand Down
12 changes: 0 additions & 12 deletions examples/with-google-tag-manager/app/layout.js

This file was deleted.

22 changes: 22 additions & 0 deletions examples/with-google-tag-manager/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { GoogleTagManager } from "@next/third-parties/google";

export const metadata: Metadata = {
title: "With Google Tag Manager",
description: "Next.js example with Google Tag Manager.",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
<GoogleTagManager
gtmId={process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID as string}
/>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventButton } from "./components/EventButton";
import { EventButton } from "@/_components/EventButton";

export default function Page() {
return (
Expand Down
11 changes: 8 additions & 3 deletions examples/with-google-tag-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"start": "next start"
},
"dependencies": {
"next": "latest",
"@next/third-parties": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"next": "latest",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/react": "^19.0.1",
"typescript": "^5.7.2"
}
}
27 changes: 27 additions & 0 deletions examples/with-google-tag-manager/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion examples/with-youtube-embed/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Example app using YouTube Embed

This example shows how to embed a YouTube Embed using `@next/third-parties`.
This example shows how to embed a YouTube Embed using [`@next/third-parties`](https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries).

## Deploy your own

Expand Down
7 changes: 0 additions & 7 deletions examples/with-youtube-embed/app/layout.js

This file was deleted.

18 changes: 18 additions & 0 deletions examples/with-youtube-embed/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "With YouTube Embed",
description: "Next.js example with YouTube Embed.",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
File renamed without changes.
11 changes: 8 additions & 3 deletions examples/with-youtube-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"start": "next start"
},
"dependencies": {
"next": "latest",
"@next/third-parties": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"next": "latest",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/react": "^19.0.1",
"typescript": "^5.7.2"
}
}
24 changes: 24 additions & 0 deletions examples/with-youtube-embed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 6a609fa

Please sign in to comment.