Unverified Commit bb7af2a0 authored by Steven's avatar Steven Committed by GitHub

chore(examples): migrate `image-component` example to App Router (#60289)

This PR migrates the `image-component` example from Pages Router to App
Router.

It also upgrades a couple dependencies and regenerates tsconfig.json
parent 0191ef85
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
import styles from '../styles.module.css' import styles from '../../styles.module.css'
import mountains from '../public/mountains.jpg' import mountains from '../../public/mountains.jpg'
const BackgroundPage = () => ( const BackgroundPage = () => (
<div> <div>
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
// Pixel GIF code adapted from https://stackoverflow.com/a/33919020/266535 // Pixel GIF code adapted from https://stackoverflow.com/a/33919020/266535
const keyStr = const keyStr =
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
import mountains from '../public/mountains.jpg' import mountains from '../../public/mountains.jpg'
const Fill = () => ( const Fill = () => (
<div> <div>
......
import '../app.css'
export const metadata = {
title: 'Image Component with Next.js',
description:
'This page demonstrates the usage of the next/image component with live examples. This component is designed to automatically optimize images on-demand as the browser requests them.',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
import mountains from '../public/mountains.jpg' import mountains from '../../public/mountains.jpg'
const PlaceholderBlur = () => ( const PlaceholderBlur = () => (
<div> <div>
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
import mountains from '../public/mountains.jpg' import mountains from '../../public/mountains.jpg'
const Responsive = () => ( const Responsive = () => (
<div> <div>
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
const shimmer = (w: number, h: number) => ` const shimmer = (w: number, h: number) => `
<svg width="${w}" height="${h}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <svg width="${w}" height="${h}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
......
import Image, { ImageProps } from 'next/image' import Image, { ImageProps } from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../../components/view-source'
import styles from '../styles.module.css' import styles from '../../styles.module.css'
// Note: we cannot use `priority` or `loading="eager" // Note: we cannot use `priority` or `loading="eager"
// because we depend on the default `loading="lazy"` // because we depend on the default `loading="lazy"`
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "18.15.3", "@types/node": "^18.19.4",
"@types/react": "18.2.8", "@types/react": "^18.2.46",
"typescript": "4.9.5" "typescript": "^5.3.3"
} }
} }
import type { AppProps } from 'next/app'
import '../app.css'
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"], "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
...@@ -10,11 +9,17 @@ ...@@ -10,11 +9,17 @@
"incremental": true, "incremental": true,
"esModuleInterop": true, "esModuleInterop": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"moduleResolution": "node" "plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment