diff --git a/.prettierrc.json b/.prettierrc.json index fd496a820e..eaaa46cd3d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,4 +1,5 @@ { + "trailingComma": "es5", "singleQuote": true, "semi": false } diff --git a/examples/.prettierrc.json b/examples/.prettierrc.json new file mode 100644 index 0000000000..a7d8824a65 --- /dev/null +++ b/examples/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "trailingComma": "all", + "singleQuote": false, + "semi": true +} diff --git a/examples/active-class-name/components/ActiveLink.tsx b/examples/active-class-name/components/ActiveLink.tsx index 5745eff025..6bae8c9639 100644 --- a/examples/active-class-name/components/ActiveLink.tsx +++ b/examples/active-class-name/components/ActiveLink.tsx @@ -1,11 +1,11 @@ -import { useRouter } from 'next/router' -import Link, { LinkProps } from 'next/link' -import React, { PropsWithChildren, useState, useEffect } from 'react' +import { useRouter } from "next/router"; +import Link, { LinkProps } from "next/link"; +import React, { PropsWithChildren, useState, useEffect } from "react"; type ActiveLinkProps = LinkProps & { - className?: string - activeClassName: string -} + className?: string; + activeClassName: string; +}; const ActiveLink = ({ children, @@ -13,8 +13,8 @@ const ActiveLink = ({ className, ...props }: PropsWithChildren) => { - const { asPath, isReady } = useRouter() - const [computedClassName, setComputedClassName] = useState(className) + const { asPath, isReady } = useRouter(); + const [computedClassName, setComputedClassName] = useState(className); useEffect(() => { // Check if the router fields are updated client-side @@ -23,19 +23,19 @@ const ActiveLink = ({ // Static route will be matched via props.href const linkPathname = new URL( (props.as || props.href) as string, - location.href - ).pathname + location.href, + ).pathname; // Using URL().pathname to get rid of query and hash - const activePathname = new URL(asPath, location.href).pathname + const activePathname = new URL(asPath, location.href).pathname; const newClassName = linkPathname === activePathname ? `${className} ${activeClassName}`.trim() - : className + : className; if (newClassName !== computedClassName) { - setComputedClassName(newClassName) + setComputedClassName(newClassName); } } }, [ @@ -46,13 +46,13 @@ const ActiveLink = ({ activeClassName, className, computedClassName, - ]) + ]); return ( {children} - ) -} + ); +}; -export default ActiveLink +export default ActiveLink; diff --git a/examples/active-class-name/components/Nav.tsx b/examples/active-class-name/components/Nav.tsx index b2f02bf985..f7b0bdaaf2 100644 --- a/examples/active-class-name/components/Nav.tsx +++ b/examples/active-class-name/components/Nav.tsx @@ -1,4 +1,4 @@ -import ActiveLink from './ActiveLink' +import ActiveLink from "./ActiveLink"; const Nav = () => ( -) +); -export default Nav +export default Nav; diff --git a/examples/active-class-name/next.config.js b/examples/active-class-name/next.config.js index 3116440794..2adf0e71e4 100644 --- a/examples/active-class-name/next.config.js +++ b/examples/active-class-name/next.config.js @@ -3,9 +3,9 @@ module.exports = { async rewrites() { return [ { - source: '/blog', - destination: '/news', + source: "/blog", + destination: "/news", }, - ] + ]; }, -} +}; diff --git a/examples/active-class-name/pages/[slug].tsx b/examples/active-class-name/pages/[slug].tsx index 0f8f73e588..7f19ea2f42 100644 --- a/examples/active-class-name/pages/[slug].tsx +++ b/examples/active-class-name/pages/[slug].tsx @@ -1,14 +1,14 @@ -import { useRouter } from 'next/router' -import Nav from '../components/Nav' +import { useRouter } from "next/router"; +import Nav from "../components/Nav"; const SlugPage = () => { - const { asPath } = useRouter() + const { asPath } = useRouter(); return ( <>