Skip to content

Commit e83e9f7

Browse files
Merge branch 'canary' into fix/initial-not-found
2 parents d16e796 + 8a80b0b commit e83e9f7

File tree

29 files changed

+351
-21
lines changed

29 files changed

+351
-21
lines changed

docs/api-reference/next/image.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ Other properties on the `<Image />` component will be passed to the underlying
263263
- `ref`. Use [`onLoadingComplete`](#onloadingcomplete) instead.
264264
- `decoding`. It is always `"async"`.
265265

266+
## Styling
267+
268+
`next/image` wraps the `img` element with other `div` elements to maintain the aspect ratio of the image and prevent [Cumulative Layout Shift](https://vercel.com/blog/core-web-vitals#cumulative-layout-shift).
269+
270+
To add styles to the underlying `img` element, pass the `className` prop to the `<Image />` component. Then, use Next.js' [built-in CSS support](/docs/basic-features/built-in-css-support.md) to add rules to that class.
271+
272+
**Note:** If using [`layout="fill"`](/docs/api-reference/next/image.md#layout), ensure the parent element uses `position: relative`.
273+
266274
## Related
267275

268276
For more information on what to do next, we recommend the following sections:

docs/basic-features/data-fetching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export async function getStaticPaths() {
424424
paths: [
425425
{ params: { ... } } // See the "paths" section below
426426
],
427-
fallback: true or false // See the "fallback" section below
427+
fallback: true, false, or 'blocking' // See the "fallback" section below
428428
};
429429
}
430430
```

examples/with-jotai/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel

examples/with-jotai/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Jotai example
2+
3+
This example shows how to integrate [Jotai](https://github.com/pmndrs/jotai) in Next.js.
4+
5+
- Jotai is a primitive and flexible state management library for React.
6+
- Jotai is TypeScript oriented and aims to expose a minimalistic API for dealing with state in a data-flow graph way.
7+
- Jotai uses the `useHydrateAtoms` hook to hydrate the value of an atom, for values that come from the server.
8+
9+
## Preview
10+
11+
Preview the example live on [StackBlitz](http://stackblitz.com/):
12+
13+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-jotai)
14+
15+
## Deploy your own
16+
17+
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
18+
19+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-jotai&project-name=with-jotai&repository-name=with-jotai)
20+
21+
## How to use
22+
23+
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
24+
25+
```bash
26+
npx create-next-app --example with-jotai with-jotai-app
27+
# or
28+
yarn create next-app --example with-jotai with-jotai-app
29+
```
30+
31+
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

examples/with-jotai/next-env.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />
3+
/// <reference types="next/image-types/global" />

examples/with-jotai/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
reactStrictMode: true,
3+
}

examples/with-jotai/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "with-jotai",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"jotai": "1.3.0",
11+
"next": "latest",
12+
"react": "17.0.2",
13+
"react-dom": "17.0.2"
14+
},
15+
"devDependencies": {
16+
"@types/react": "17.0.16",
17+
"eslint": "7.32.0",
18+
"eslint-config-next": "11.0.1",
19+
"typescript": "4.3.5"
20+
},
21+
"license": "MIT"
22+
}

examples/with-jotai/pages/_app.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '../styles/globals.css'
2+
import type { AppProps } from 'next/app'
3+
4+
export default function MyApp({ Component, pageProps }: AppProps) {
5+
return <Component {...pageProps} />
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
4+
type Data = {
5+
name: string
6+
}
7+
8+
export default function handler(
9+
req: NextApiRequest,
10+
res: NextApiResponse<Data>
11+
) {
12+
res.status(200).json({ name: 'John Doe' })
13+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { GetServerSideProps, InferGetServerSidePropsType } from 'next'
2+
import Head from 'next/head'
3+
import Image from 'next/image'
4+
import styles from '../styles/Home.module.css'
5+
import { atom, useAtom } from 'jotai'
6+
import { useAtomValue, useHydrateAtoms } from 'jotai/utils'
7+
8+
const countAtom = atom(0)
9+
const doubleAtom = atom((get) => get(countAtom) * 2)
10+
11+
export const getServerSideProps: GetServerSideProps<{
12+
initialCount: number
13+
}> = async (context) => {
14+
return { props: { initialCount: 42 } }
15+
}
16+
17+
export default function Home({
18+
initialCount,
19+
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
20+
useHydrateAtoms([[countAtom, initialCount]] as const)
21+
const [count, setCount] = useAtom(countAtom)
22+
const doubleCount = useAtomValue(doubleAtom)
23+
return (
24+
<div className={styles.container}>
25+
<Head>
26+
<title>with-jotai</title>
27+
<meta name="description" content="Generated by create next app" />
28+
<link rel="icon" href="/favicon.ico" />
29+
</Head>
30+
<h1 className={styles.title}>With Jotai example</h1>
31+
<main className={styles.main}>
32+
<div>Initial count from the server: {count}</div>
33+
<div>Double count: {doubleCount}</div>
34+
<button onClick={() => setCount((count) => count + 1)}>+1</button>
35+
</main>
36+
<footer className={styles.footer}>
37+
<a
38+
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
39+
target="_blank"
40+
rel="noopener noreferrer"
41+
>
42+
Powered by{' '}
43+
<span className={styles.logo}>
44+
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
45+
</span>
46+
</a>
47+
</footer>
48+
</div>
49+
)
50+
}

0 commit comments

Comments
 (0)