Skip to content

Commit 2efd888

Browse files
authored
Merge branch 'canary' into external-helper-build
2 parents dee085e + 3a22c4c commit 2efd888

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed

examples/active-class-name/components/ActiveLink.js renamed to examples/active-class-name/components/ActiveLink.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { useState, useEffect } from 'react'
21
import { useRouter } from 'next/router'
3-
import PropTypes from 'prop-types'
4-
import Link from 'next/link'
5-
import React, { Children } from 'react'
2+
import Link, { LinkProps } from 'next/link'
3+
import React, { useState, useEffect, ReactElement, Children } from 'react'
64

7-
const ActiveLink = ({ children, activeClassName, ...props }) => {
5+
type ActiveLinkProps = LinkProps & {
6+
children: ReactElement
7+
activeClassName: string
8+
}
9+
10+
const ActiveLink = ({
11+
children,
12+
activeClassName,
13+
...props
14+
}: ActiveLinkProps) => {
815
const { asPath, isReady } = useRouter()
916

1017
const child = Children.only(children)
@@ -16,8 +23,10 @@ const ActiveLink = ({ children, activeClassName, ...props }) => {
1623
if (isReady) {
1724
// Dynamic route will be matched via props.as
1825
// Static route will be matched via props.href
19-
const linkPathname = new URL(props.as || props.href, location.href)
20-
.pathname
26+
const linkPathname = new URL(
27+
(props.as || props.href) as string,
28+
location.href
29+
).pathname
2130

2231
// Using URL().pathname to get rid of query and hash
2332
const activePathname = new URL(asPath, location.href).pathname
@@ -51,8 +60,4 @@ const ActiveLink = ({ children, activeClassName, ...props }) => {
5160
)
5261
}
5362

54-
ActiveLink.propTypes = {
55-
activeClassName: PropTypes.string.isRequired,
56-
}
57-
5863
export default ActiveLink
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/active-class-name/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
},
88
"dependencies": {
99
"next": "latest",
10-
"react": "^17.0.2",
11-
"react-dom": "^17.0.2",
12-
"prop-types": "^15.7.2"
10+
"react": "18.1.0",
11+
"react-dom": "18.1.0"
12+
},
13+
"devDependencies": {
14+
"@types/node": "17.0.42",
15+
"@types/react": "18.0.12",
16+
"@types/react-dom": "18.0.5",
17+
"typescript": "4.7.3"
1318
}
1419
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve",
16+
"incremental": true
17+
},
18+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19+
"exclude": ["node_modules"]
20+
}

0 commit comments

Comments
 (0)