diff --git a/examples/nextjs-13/.gitignore b/examples/nextjs-13/.gitignore new file mode 100644 index 00000000000000..1437c53f70bc21 --- /dev/null +++ b/examples/nextjs-13/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel diff --git a/examples/nextjs-13/README.md b/examples/nextjs-13/README.md new file mode 100644 index 00000000000000..50159307630c0c --- /dev/null +++ b/examples/nextjs-13/README.md @@ -0,0 +1,46 @@ +# Next.js example + +## How to use + +Download the example [or clone the repo](https://github.com/mui/material-ui): + + + +```sh +curl https://codeload.github.com/mui/material-ui/tar.gz/master | tar -xz --strip=2 material-ui-master/examples/nextjs-13 +cd nextjs +``` + +Install it and run: + +```sh +npm install +npm run dev +``` + +or: + + + +[![Edit on StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/mui/material-ui/tree/master/examples/nextjs-13) + +[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/mui/material-ui/tree/master/examples/nextjs-13) + +## The idea behind the example + +The project uses [Next.js](https://github.com/vercel/next.js), which is a framework for server-rendered React apps. +It includes `@mui/material` and its peer dependencies, including `emotion`, the default style engine in MUI v5. +If you prefer, you can [use styled-components instead](https://mui.com/material-ui/guides/interoperability/#styled-components). +This examples uses the new experimental features of Next.js 13 - the app directory and client components. + +## The link component + +The [example folder](https://github.com/mui/material-ui/tree/HEAD/examples/nextjs-with-typescript) provides an adapter for the use of [Next.js's Link component](https://nextjs.org/docs/api-reference/next/link) with MUI. +More information [in the documentation](https://mui.com/material-ui/guides/routing/#next-js). + +## What's next? + + + +You now have a working example project. +You can head back to the documentation, continuing browsing it from the [templates](https://mui.com/material-ui/getting-started/templates/) section. diff --git a/examples/nextjs-13/app/emotion.js b/examples/nextjs-13/app/emotion.js new file mode 100644 index 00000000000000..b34f6a1487c564 --- /dev/null +++ b/examples/nextjs-13/app/emotion.js @@ -0,0 +1,33 @@ +'use client'; + +import * as React from 'react'; +import PropTypes from 'prop-types'; +import { CacheProvider } from '@emotion/react'; +import { useServerInsertedHTML } from 'next/navigation'; +import createEmotionCache from '../src/createEmotionCache'; + +export default function RootStyleRegistry({ children }) { + const [cache] = React.useState(() => { + const c = createEmotionCache(); + c.compat = true; + return c; + }); + + useServerInsertedHTML(() => { + return ( +