adding-examples
Adding examples​
When you add an example to the examples directory, please follow these guidelines to ensure high-quality examples:
- TypeScript should be leveraged for new examples (no need for separate JavaScript and TypeScript examples, converting old JavaScript examples is preferred)
- Examples should not add custom ESLint configuration (we have specific templates for ESLint)
- If API routes aren't used in an example, they should be omitted
- If an example exists for a certain library and you would like to showcase a specific feature of that library, the existing example should be updated (instead of adding a new example)
- Package manager specific config should not be added (e.g.
resolutionsinpackage.json) - In
package.jsonthe version ofnextshould belatest - In
package.jsonthe dependency versions should be up-to-date - Use
export default functionfor page components and API Routes instead ofconst/let(The exception is if the page hasgetInitialProps, in which caseNextPagecould be useful) - CMS example directories should be prefixed with
cms- - Example directories should not be prefixed with
with- - Make sure linting passes (you can run
pnpm build && pnpm lintto verify andpnpm lint-fixfor automatic fixes)
Also, don’t forget to add a README.md file with the following format:
- Replace
DIRECTORY_NAMEwith the directory name you’re adding. - Fill in
Example NameandDescription. - Examples should be TypeScript first, if possible.
- Omit the
nameandversionfields from yourpackage.json. - Ensure all your dependencies are up to date.
- Ensure you’re using
next/image. - To add additional installation instructions, please add them where appropriate.
- To add additional notes, add
## Notessection at the end. - Remove the
Deploy your ownsection if your example can’t be immediately deployed to Vercel.
# Example Name
Description
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/DIRECTORY_NAME&project-name=DIRECTORY_NAME&repository-name=DIRECTORY_NAME)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), [pnpm](https://pnpm.io), or [Bun](https://bun.sh/docs/cli/bunx) to bootstrap the example:
```bash
npx create-next-app --example DIRECTORY_NAME DIRECTORY_NAME-app
```
```bash
yarn create next-app --example DIRECTORY_NAME DIRECTORY_NAME-app
```
```bash
pnpm create next-app --example DIRECTORY_NAME DIRECTORY_NAME-app
```
```bash
bunx create-next-app --example DIRECTORY_NAME DIRECTORY_NAME-app
```
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)).