Dataset Viewer
Auto-converted to Parquet Duplicate
instruction
stringlengths
31
302
output
stringlengths
22
4.36k
source_url
stringlengths
41
99
How do I implement With the default template in Next.js?
To create a new app using the default template, run the following command in your terminal: You will then be asked the following prompts: Once you've answered the prompts, a new project will be created with your chosen configuration. ```bash npx create-next-app@latest ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/cli/create-next-app
How do I implement With any public GitHub example in Next.js?
To create a new app using any public GitHub example, use the --example option with the GitHub repo's URL. For example: Was this helpful? ```bash npx create-next-app@latest --example "https://github.com/.../" [your-project-name] ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/cli/create-next-app
How do I implement className in Next.js?
Returns a read-only CSS className for the loaded font to be passed to an HTML element. ```jsx <p className={inter.className}>Hello, Next.js!</p> ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/font
How do I implement style in Next.js?
Returns a read-only CSS style object for the loaded font to be passed to an HTML element, including style.fontFamily to access the font family name and fallback fonts. ```jsx <p style={inter.style}>Hello World</p> ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/font
How do I implement CSS Variables in Next.js?
If you would like to set your styles in an external style sheet and specify additional options there, use the CSS variable method. In addition to importing the font, also import the CSS file where the CSS variable is defined and set the variable option of the font loader object as follows: To use the font, set the clas...
https://nextjs.org/docs/app/api-reference/components/font
How do I implement Using a font definitions file in Next.js?
For example, create a fonts.ts file in a styles folder at the root of your app directory. Then, specify your font definitions as follows: You can now use these definitions in your code as follows: To make it easier to access the font definitions in your code, you can define a path alias in your tsconfig.json or jsconfi...
https://nextjs.org/docs/app/api-reference/components/font
What are the best practices for Using a font definitions file in Next.js?
```typescript import { Inter, Lora, Source_Sans_3 } from 'next/font/google' import localFont from 'next/font/local' // define your variable fonts const inter = Inter() const lora = Lora() // define 2 weights of a non-variable font const sourceCodePro400 = Source_Sans_3({ weight: '400' }) const sourceCodePro700 = Sou...
https://nextjs.org/docs/app/api-reference/components/font
How do I implement Form in Next.js?
It's useful for forms that update URL search params as it reduces the boilerplate code needed to achieve the above. Basic usage: ```javascript import Form from 'next/form' export default function Search() { return ( <Form action="/search"> {/* On submission, the input value will be appended to t...
https://nextjs.org/docs/app/api-reference/components/form
How do I implement Search form that leads to a search result page in Next.js?
You can create a search form that navigates to a search results page by passing the path as an action: When the user updates the query input field and submits the form, the form data will be encoded into the URL as search params, e.g. /search?query=abc. Good to know: If you pass an empty string "" to action, the form w...
https://nextjs.org/docs/app/api-reference/components/form
How do I implement Mutations with Server Actions in Next.js?
You can perform mutations by passing a function to the action prop. Good to know: Since the "destination" of the form submission is not known until the action is executed, <Form> cannot automatically prefetch shared UI. Then, in the new page, you can fetch data using the params prop: See the Server Actions docs for mor...
https://nextjs.org/docs/app/api-reference/components/form
How do I implement Image in Next.js?
This API reference will help you understand how to use props and configuration options available for the Image Component. For features and usage, please see the Image Component page. ```javascript import Image from 'next/image' export default function Page() { return ( <Image src="/profile.png" widt...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Required Props in Next.js?
The Image Component requires the following properties: src, alt, width and height (or fill). ```javascript import Image from 'next/image' export default function Page() { return ( <div> <Image src="/profile.png" width={500} height={500} alt="Picture of the author" /> ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement loader in Next.js?
A custom function used to resolve image URLs. A loader is a function returning a URL string for the image, given the following parameters: Here is an example of using a custom loader: Good to know: Using props like loader, which accept a function, requires using Client Components to serialize the provided function. ```...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement fill in Next.js?
A boolean that causes the image to fill the parent element, which is useful when the width and height are unknown. The parent element must assign position: "relative", position: "fixed", or position: "absolute" style. By default, the img element will automatically be assigned the position: "absolute" style. If no style...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement sizes in Next.js?
A string, similar to a media query, that provides information about how wide the image will be at different breakpoints. The value of sizes will greatly affect performance for images using fill or which are styled to have a responsive size. The sizes property serves two important purposes related to image performance: ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement quality in Next.js?
The quality of the optimized image, an integer between 1 and 100, where 100 is the best quality and therefore largest file size. Defaults to 75. Good to know: If the original source image was already low quality, setting the quality prop too high could cause the resulting optimized image to be larger than the original ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement priority in Next.js?
Should only be used when the image is visible above the fold. Defaults to false. ```jsx priority={false} // {false} | {true} ``` ## Best Practices - You should use the priority property on any image detected as the Largest Contentful Paint (LCP) element. It may be appropriate to have multiple priority images, as diffe...
https://nextjs.org/docs/app/api-reference/components/image
What are the best practices for priority in Next.js?
```jsx priority={false} // {false} | {true} ``` ## Best Practices - You should use the priority property on any image detected as the Largest Contentful Paint (LCP) element. It may be appropriate to have multiple priority images, as different images may be the LCP element for different viewport sizes. Version info:...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement style in Next.js?
Allows passing CSS styles to the underlying image element. Remember that the required width and height props can interact with your styling. If you use styling to modify an image's width, you should also style its height to auto to preserve its intrinsic aspect ratio, or your image will be distorted. ```javascript cons...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement onLoadingComplete in Next.js?
A callback function that is invoked once the image is completely loaded and the placeholder has been removed. The callback function will be called with one argument, a reference to the underlying <img> element. Good to know: Using props like onLoadingComplete, which accept a function, requires using Client Components t...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement onLoad in Next.js?
A callback function that is invoked once the image is completely loaded and the placeholder has been removed. The callback function will be called with one argument, the Event which has a target that references the underlying <img> element. Good to know: Using props like onLoad, which accept a function, requires using ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement loading in Next.js?
The loading behavior of the image. Defaults to lazy. When lazy, defer loading the image until it reaches a calculated distance from the viewport. When eager, load the image immediately. Learn more about the loading attribute. ```jsx loading = 'lazy' // {lazy} | {eager} ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/image
What are the best practices for blurDataURL in Next.js?
## Best Practices - Must be a base64-encoded image. It will be enlarged and blurred, so a very small image (10px or less) is recommended. Including larger images as placeholders may harm your application performance. Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/image
How do I implement unoptimized in Next.js?
When true, the source image will be served as-is from the src instead of changing quality, size, or format. Defaults to false. This is useful for images that do not benefit from optimization such as small images (less than 1KB), vector images (SVG), or animated images (GIF). ```jsx unoptimized = {false} // {false} | {t...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement overrideSrc in Next.js?
When providing the src prop to the <Image> component, both the srcset and src attributes are generated automatically for the resulting <img>. In some cases, it is not desirable to have the src attribute generated and you may wish to override it using the overrideSrc prop. For example, when upgrading an existing website...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement remotePatterns in Next.js?
Wildcard patterns can be used for both pathname and hostname and have the following syntax: * match a single path segment or subdomain ** match any number of path segments at the end or subdomains at the beginning The ** syntax does not work in the middle of the pattern. ```javascript module.exports = { images: { ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement domains in Next.js?
Similar to remotePatterns, the domains configuration can be used to provide a list of allowed hostnames for external images. ```javascript module.exports = { images: { domains: ['assets.acme.com'], }, } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/image
How do I implement loaderFile in Next.js?
Examples: Custom Image Loader Configuration Good to know: Customizing the image loader file, which accepts a function, requires using Client Components to serialize the provided function. ```javascript module.exports = { images: { loader: 'custom', loaderFile: './my/image/loader.js', }, } ``` ```javascript ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement deviceSizes in Next.js?
If no configuration is provided, the default below is used. ```javascript module.exports = { images: { deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840], }, } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/components/image
How do I implement imageSizes in Next.js?
The reason there are two separate lists is that imageSizes is only used for images which provide a sizes prop, which indicates that the image is less than the full width of the screen. Therefore, the sizes in imageSizes should all be smaller than the smallest size in deviceSizes. If no configuration is provided, the de...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement formats in Next.js?
The default Image Optimization API will automatically detect the browser's supported image formats via the request's Accept header in order to determine the best output format. If the Accept header matches more than one of the configured formats, the first match in the array is used. Therefore, the array order matters....
https://nextjs.org/docs/app/api-reference/components/image
What are the best practices for Caching Behavior in Next.js?
## Best Practices - You can configure minimumCacheTTL to increase the cache duration when the upstream image does not include Cache-Control header or the value is very low. You can configure deviceSizes and imageSizes to reduce the total number of possible generated images. You can configure formats to disable multip...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement minimumCacheTTL in Next.js?
You can configure the Time to Live (TTL) in seconds for cached optimized images. In many cases, it's better to use a Static Image Import which will automatically hash the file contents and cache the image forever with a Cache-Control header of immutable. If no configuration is provided, the default below is used. You c...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement disableStaticImages in Next.js?
The default behavior allows you to import static files such as import icon from './icon.png' and then pass that to the src property. In some cases, you may wish to disable this feature if it conflicts with other plugins that expect the import to behave differently. ```javascript module.exports = { images: { disab...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement dangerouslyAllowSVG in Next.js?
The default loader does not optimize SVG images for a few reasons. First, SVG is a vector format meaning it can be resized losslessly. Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper Content Security Policy (CSP) headers. ```javascript module.exports = { images:...
https://nextjs.org/docs/app/api-reference/components/image
What are the best practices for dangerouslyAllowSVG in Next.js?
```javascript module.exports = { images: { dangerouslyAllowSVG: true, contentDispositionType: 'attachment', contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", }, } ``` ## Best Practices - Therefore, we recommended using the unoptimized prop when the src prop is known to be SVG. ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement contentDispositionType in Next.js?
The default loader sets the Content-Disposition header to attachment for added protection since the API can serve arbitrary remote images. The default value is attachment which forces the browser to download the image when visiting directly. This is particularly important when dangerouslyAllowSVG is true. You can optio...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Responsive image using a static import in Next.js?
If the source image is not dynamic, you can statically import to create a responsive image: Try it out: Demo the image responsive to viewport ```javascript import Image from 'next/image' import me from '../photos/me.jpg' export default function Author() { return ( <Image src={me} alt="Picture of the...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Responsive image with aspect ratio in Next.js?
If the source image is a dynamic or a remote url, you will also need to provide width and height to set the correct aspect ratio of the responsive image: Try it out: Demo the image responsive to viewport ```javascript import Image from 'next/image' export default function Page({ photoUrl }) { return ( <Image ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Responsive image with fill in Next.js?
If you don't know the aspect ratio, you will need to set the fill prop and set position: relative on the parent. Optionally, you can set object-fit style depending on the desired stretch vs crop behavior: Try it out: ```javascript import Image from 'next/image' export default function Page({ photoUrl }) { return ( ...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Theme Detection CSS in Next.js?
If you want to display a different image for light and dark mode, you can create a new component that wraps two <Image> components and reveals the correct one based on a CSS media query. Good to know: The default behavior of loading="lazy" ensures that only the correct image is loaded. You cannot use priority or loadin...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Theme Detection Picture in Next.js?
If you want to display a different image for light and dark mode, you can use the <picture> element to display a different image based on the user's preferred color scheme. ```javascript import { getImageProps } from 'next/image' export default function Page() { const common = { alt: 'Theme Example', width: 800, he...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Art Direction in Next.js?
If you want to display a different image for mobile and desktop, sometimes called Art Direction, you can provide different src, width, height, and quality props to getImageProps(). ```javascript import { getImageProps } from 'next/image' export default function Home() { const common = { alt: 'Art Direction Example'...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement Background CSS in Next.js?
You can even convert the srcSet string to the image-set() CSS function to optimize a background image. ```javascript import { getImageProps } from 'next/image' function getBackgroundImage(srcSet = '') { const imageSet = srcSet .split(', ') .map((str) => { const [url, dpi] = str.split(' ') return...
https://nextjs.org/docs/app/api-reference/components/image
How do I implement S in Next.js?
This API reference will help you understand how to use props available for the Script Component. For features and usage, please see the Optimizing Scripts page. ```javascript import Script from 'next/script' export default function Dashboard() { return ( <> <Script src="https://example.com/script.js" /> ...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement beforeInteractive in Next.js?
Scripts denoted with this strategy are preloaded and fetched before any first-party code, but their execution does not block page hydration from occurring. beforeInteractive scripts must be placed inside the root layout (app/layout.tsx) and are designed to load scripts that are needed by the entire site (i.e. the scrip...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement afterInteractive in Next.js?
afterInteractive scripts can be placed inside of any page or layout and will only load and execute when that page (or group of pages) is opened in the browser. Some examples of scripts that are good candidates for afterInteractive include: ```javascript import Script from 'next/script' export default function Page() ...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement lazyOnload in Next.js?
Scripts that use the lazyOnload strategy are injected into the HTML client-side during browser idle time and will load after all resources on the page have been fetched. This strategy should be used for any background or low priority scripts that do not need to load early. lazyOnload scripts can be placed inside of any...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement worker in Next.js?
Scripts that use the worker strategy are off-loaded to a web worker in order to free up the main thread and ensure that only critical, first-party resources are processed on it. While this strategy can be used for any script, it is an advanced use case that is not guaranteed to support all third-party scripts. worker s...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement onLoad in Next.js?
Some third-party scripts require users to run JavaScript code once after the script has finished loading in order to instantiate content or call a function. If you are loading a script with either afterInteractive or lazyOnload as a loading strategy, you can execute code after it has loaded using the onLoad property. H...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement onReady in Next.js?
Here's an example of how to re-instantiate a Google Maps JS embed every time the component is mounted: ```jsx 'use client' import { useRef } from 'react' import Script from 'next/script' export default function Page() { const mapRef = useRef() return ( <> <div ref={mapRef}></div> <Script ...
https://nextjs.org/docs/app/api-reference/components/script
How do I implement Specifying a root directory within a monorepo in Next.js?
rootDir can be a path (relative or absolute), a glob (i.e. "packages/*/"), or an array of paths and/or globs. ```jsx import { FlatCompat } from '@eslint/eslintrc' const compat = new FlatCompat({ // import.meta.dirname is available after Node.js v20.11.0 baseDirectory: import.meta.dirname, }) const eslintConfig = ...
https://nextjs.org/docs/app/api-reference/config/eslint
What are the best practices for With TypeScript in Next.js?
```jsx import { FlatCompat } from '@eslint/eslintrc' const compat = new FlatCompat({ // import.meta.dirname is available after Node.js v20.11.0 baseDirectory: import.meta.dirname, }) const eslintConfig = [ ...compat.config({ extends: ['next/core-web-vitals', 'next/typescript'], }), ] export default esli...
https://nextjs.org/docs/app/api-reference/config/eslint
How do I implement With Prettier in Next.js?
ESLint also contains code formatting rules, which can conflict with your existing Prettier setup. We recommend including eslint-config-prettier in your ESLint config to make ESLint and Prettier work together. First, install the dependency: Then, add prettier to your existing ESLint config: ```bash npm install --save-de...
https://nextjs.org/docs/app/api-reference/config/eslint
How do I implement TypeScript in Next.js?
However, none of the configs are required, and it's not necessary to understand what each config does. Instead, search for the features you need to enable or modify in this section and they will show you what to do. This page documents all the available configuration options: ```jsx import type { NextConfig } from 'nex...
https://nextjs.org/docs/app/api-reference/config/next-config-js
How do I implement Set up a CDN in Next.js?
Would instead become: Files in the public folder; if you want to serve those assets over a CDN, you'll have to introduce the prefix yourself Was this helpful? ```jsx // @ts-check import { PHASE_DEVELOPMENT_SERVER } from 'next/constants' export default (phase) => { const isDev = phase === PHASE_DEVELOPMENT_SERVER ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix
How do I implement in Next.js?
Good to know: This value must be set at build time and cannot be changed without re-building as the value is inlined in the client-side bundles. ```javascript module.exports = { basePath: '/docs', } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
How do I implement Links in Next.js?
For example, using /about will automatically become /docs/about when basePath is set to /docs. Output html: This makes sure that you don't have to change all links in your application when changing the basePath value. ```javascript export default function HomePage() { return ( <> <Link href="/about">About P...
https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
How do I implement Images in Next.js?
For example, using /docs/me.png will properly serve your image when basePath is set to /docs. Was this helpful? ```jsx import Image from 'next/image' function Home() { return ( <> <h1>My Homepage</h1> <Image src="/docs/me.png" alt="Picture of the author" width={500} h...
https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
How do I implement Usage in Next.js?
You can now use this custom blog configuration in your component or function as follows: ```css module.exports = { experimental: { dynamicIO: true, cacheLife: { blog: { stale: 3600, // 1 hour revalidate: 900, // 15 minutes expire: 86400, // 1 day }, }, }, } ``` ```jav...
https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheLife
How do I implement Disabling compression in Next.js?
To disable compression, set the compress config option to false: We do not recommend disabling compression unless you have compression configured on your server, as compression reduces bandwidth usage and improves the performance of your application. ```javascript module.exports = { compress: false, } ``` Version in...
https://nextjs.org/docs/app/api-reference/config/next-config-js/compress
How do I implement in Next.js?
CSS Chunking is a strategy used to improve the performance of your web application by splitting and re-ordering CSS files into chunks. This allows you to load only the CSS that is needed for a specific route, instead of loading all the application's CSS at once. ```typescript /** @type {import('next').NextConfig} */ co...
https://nextjs.org/docs/app/api-reference/config/next-config-js/cssChunking
How do I implement in Next.js?
distDir should not leave your project directory. For example, ../build is an invalid directory. Was this helpful? ```javascript module.exports = { distDir: 'build', } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/config/next-config-js/distDir
How do I implement Usage in Next.js?
When dynamicIO is enabled, you can use the following cache functions and configurations: The use cache directive The cacheLife function with use cache The cacheTag function ```jsx import type { NextConfig } from 'next' const nextConfig: NextConfig = { experimental: { dynamicIO: true, }, } export default nex...
https://nextjs.org/docs/app/api-reference/config/next-config-js/dynamicIO
How do I implement env in Next.js?
Now you can access process.env.customKey in your code. For example: For example, the following line: Will end up being: Was this helpful? ```javascript module.exports = { env: { customKey: 'my-value', }, } ``` ```jsx function Page() { return <h1>The value of customKey is: {process.env.customKey}</h1> } expo...
https://nextjs.org/docs/app/api-reference/config/next-config-js/env
How do I implement in Next.js?
You can specify a custom stale-while-revalidate expire time for CDNs to consume in the Cache-Control header for ISR enabled pages. Now when sending the Cache-Control header the expire time will be calculated depending on the specific revalidate period. For example, if you have a revalidate of 15 minutes on a path and t...
https://nextjs.org/docs/app/api-reference/config/next-config-js/expireTime
How do I implement in Next.js?
Let's start with an example, to create a custom exportPathMap for an app with the following pages: The pages will then be exported as HTML files, for example, /about will become /about.html. The returned object is a map of pages where the key is the pathname and the value is an object that accepts the following fields:...
https://nextjs.org/docs/app/api-reference/config/next-config-js/exportPathMap
How do I implement in Next.js?
Headers allow you to set custom HTTP headers on the response to an incoming request on a given path. headers is an async function that expects an array to be returned holding objects with source and headers properties: source is the incoming request path pattern. headers is an array of response header objects, with key...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Header Overriding Behavior in Next.js?
If two headers match the same path and set the same header key, the last header key will override the first. Using the below headers, the path /hello will result in the header x-hello being world due to the last header value set being world. ```javascript module.exports = { async headers() { return [ { ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Path Matching in Next.js?
Path matches are allowed, for example /blog/:slug will match /blog/hello-world (no nested paths): ```javascript module.exports = { async headers() { return [ { source: '/blog/:slug', headers: [ { key: 'x-slug', value: ':slug', // Matched parameters can be us...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Wildcard Path Matching in Next.js?
To match a wildcard path you can use * after a parameter, for example /blog/:slug* will match /blog/a/b/c/d/hello-world: ```javascript module.exports = { async headers() { return [ { source: '/blog/:slug*', headers: [ { key: 'x-slug', value: ':slug*', // Mat...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Regex Path Matching in Next.js?
To match a regex path you can wrap the regex in parenthesis after a parameter, for example /blog/:slug(\\d{1,}) will match /blog/123 but not /blog/abc: The following characters (, ), {, }, :, *, +, ? are used for regex path matching, so when used in the source as non-special values they must be escaped by adding \\ bef...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Header, Cookie, and Query Matching in Next.js?
To only apply a header when header, cookie, or query values also match the has field or don't match the missing field can be used. Both the source and all has items must match and all missing items must not match for the header to be applied. has and missing items can have the following fields: type: String - must be e...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Headers with basePath support in Next.js?
When leveraging basePath support with headers each source is automatically prefixed with the basePath unless you add basePath: false to the header: ```javascript module.exports = { basePath: '/docs', async headers() { return [ { source: '/with-basePath', // becomes /docs/with-basePath he...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement Headers with i18n support in Next.js?
When leveraging i18n support with headers each source is automatically prefixed to handle the configured locales unless you add locale: false to the header. If locale: false is used you must prefix the source with a locale for it to be matched correctly. ```javascript module.exports = { i18n: { locales: ['en', 'f...
https://nextjs.org/docs/app/api-reference/config/next-config-js/headers
How do I implement in Next.js?
Good to know: Customizing the image loader file, which accepts a function, requires using Client Components to serialize the provided function. To learn more about configuring the behavior of the built-in Image Optimization API and the Image Component, see Image Configuration Options for available options. ```javascrip...
https://nextjs.org/docs/app/api-reference/config/next-config-js/images
How do I implement in Next.js?
Caching and revalidating pages (with Incremental Static Regeneration) use the same shared cache. When deploying to Vercel, the ISR cache is automatically persisted to durable storage. View an example of a custom cache handler and learn more about implementation. ```javascript module.exports = { cacheHandler: require....
https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath
How do I implement Usage in Next.js?
Experimental support for inlining CSS in the <head>. When this flag is enabled, all places where we normally generate a <link> tag will instead have a generated <style> tag. ```typescript /** @type {import('next').NextConfig} */ const nextConfig = { experimental: { inlineCss: true, }, } module.exports = nextC...
https://nextjs.org/docs/app/api-reference/config/next-config-js/inlineCss
How do I implement Fetching in Next.js?
Any fetch requests that are restored from the Server Components HMR cache are not logged by default. However, this can be enabled by setting logging.fetches.hmrRefreshes to true. ```javascript module.exports = { logging: { fetches: { fullUrl: true, }, }, } ``` ```javascript module.exports = { loggin...
https://nextjs.org/docs/app/api-reference/config/next-config-js/logging
How do I implement Incoming Requests in Next.js?
By default all the incoming requests will be logged in the console during development. You can use the incomingRequests option to decide which requests to ignore. Since this is only logged in development, this option doesn't affect production builds. Or you can disable incoming request logging by setting incomingReques...
https://nextjs.org/docs/app/api-reference/config/next-config-js/logging
How do I implement Disabling Logging in Next.js?
In addition, you can disable the development logging by setting logging to false. Was this helpful? ```javascript module.exports = { logging: false, } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/config/next-config-js/logging
How do I implement in Next.js?
Adding a package to experimental.optimizePackageImports will only load the modules you are actually using, while still giving you the convenience of writing import statements with many named exports. The following libraries are optimized by default: Was this helpful? ```javascript module.exports = { experimental: { ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/optimizePackageImports
How do I implement Automatically Copying Traced Files in Next.js?
To start your minimal server.js file locally, run the following command: Good to know: If your project needs to listen to a specific port or hostname, you can define PORT or HOSTNAME environment variables before running server.js. For example, run PORT=8080 HOSTNAME=0.0.0.0 node server.js to start the server on http://...
https://nextjs.org/docs/app/api-reference/config/next-config-js/output
How do I implement Caveats in Next.js?
Note: The key of outputFileTracingIncludes/outputFileTracingExcludes is a glob, so special characters need to be escaped. ```javascript module.exports = { // this includes files from the monorepo base two directories up outputFileTracingRoot: path.join(__dirname, '../../'), } ``` ```javascript module.exports = { ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/output
How do I implement Incremental Adoption (Version 15) in Next.js?
Good to know: Routes that don't have experimental_ppr will default to false and will not be prerendered using PPR. You need to explicitly opt-in to PPR for each route. experimental_ppr will apply to all children of the route segment, including nested layouts and pages. You don't have to add it to every file, only the t...
https://nextjs.org/docs/app/api-reference/config/next-config-js/ppr
How do I implement in Next.js?
Source Maps are enabled by default during development. During production builds, they are disabled to prevent you leaking your source on the client, unless you specifically opt-in with the configuration flag. Was this helpful? ```javascript module.exports = { productionBrowserSourceMaps: true, } ``` Version info: 15...
https://nextjs.org/docs/app/api-reference/config/next-config-js/productionBrowserSourceMaps
How do I implement Annotations in Next.js?
You can configure the compiler to run in "opt-in" mode as follows: Then, you can annotate specific components or hooks with the "use memo" directive from React to opt-in: Note: You can also use the "use no memo" directive from React for the opposite effect, to opt-out a component or hook. Was this helpful? ```typescrip...
https://nextjs.org/docs/app/api-reference/config/next-config-js/reactCompiler
How do I implement in Next.js?
Good to know: This option is only available in App Router. Depending on the type of proxy between the browser and the server, the headers can be truncated. For example, if you are using a reverse proxy that doesn't support long headers, you should set a lower value to ensure that the headers are not truncated. Was this...
https://nextjs.org/docs/app/api-reference/config/next-config-js/reactMaxHeadersLength
How do I implement in Next.js?
If you or your team are not ready to use Strict Mode in your entire application, that's OK! You can incrementally migrate on a page-by-page basis using <React.StrictMode>. Was this helpful? ```javascript module.exports = { reactStrictMode: true, } ``` Version info: 15.2.1
https://nextjs.org/docs/app/api-reference/config/next-config-js/reactStrictMode
How do I implement in Next.js?
Redirects allow you to redirect an incoming request path to a different destination path. redirects is an async function that expects an array to be returned holding objects with source, destination, and permanent properties: source is the incoming request path pattern. destination is the path you want to route to. per...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement Path Matching in Next.js?
Path matches are allowed, for example /old-blog/:slug will match /old-blog/hello-world (no nested paths): ```javascript module.exports = { async redirects() { return [ { source: '/old-blog/:slug', destination: '/news/:slug', // Matched parameters can be used in the destination perman...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement Regex Path Matching in Next.js?
To match a regex path you can wrap the regex in parentheses after a parameter, for example /post/:slug(\\d{1,}) will match /post/123 but not /post/abc: The following characters (, ), {, }, :, *, +, ? are used for regex path matching, so when used in the source as non-special values they must be escaped by adding \\ bef...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement Header, Cookie, and Query Matching in Next.js?
To only match a redirect when header, cookie, or query values also match the has field or don't match the missing field can be used. Both the source and all has items must match and all missing items must not match for the redirect to be applied. has and missing items can have the following fields: type: String - must ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement Redirects with basePath support in Next.js?
When leveraging basePath support with redirects each source and destination is automatically prefixed with the basePath unless you add basePath: false to the redirect: ```javascript module.exports = { basePath: '/docs', async redirects() { return [ { source: '/with-basePath', // automatically be...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement Redirects with i18n support in Next.js?
When leveraging i18n support with redirects each source and destination is automatically prefixed to handle the configured locales unless you add locale: false to the redirect. If locale: false is used you must prefix the source and destination with a locale for it to be matched correctly. In some rare cases, you might...
https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects
How do I implement in Next.js?
Rewrites allow you to map an incoming request path to a different destination path. Rewrites act as a URL proxy and mask the destination path, making it appear the user hasn't changed their location on the site. In contrast, redirects will reroute to a new page and show the URL changes. Rewrites are applied to client-s...
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
How do I implement Rewrite parameters in Next.js?
When using parameters in a rewrite the parameters will be passed in the query by default when none of the parameters are used in the destination. If a parameter is used in the destination none of the parameters will be automatically passed in the query. You can still pass the parameters manually in the query if one is ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
How do I implement Regex Path Matching in Next.js?
To match a regex path you can wrap the regex in parenthesis after a parameter, for example /blog/:slug(\\d{1,}) will match /blog/123 but not /blog/abc: The following characters (, ), {, }, [, ], |, \, ^, ., :, *, +, -, ?, $ are used for regex path matching, so when used in the source as non-special values they must be ...
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
How do I implement Header, Cookie, and Query Matching in Next.js?
To only match a rewrite when header, cookie, or query values also match the has field or don't match the missing field can be used. Both the source and all has items must match and all missing items must not match for the rewrite to be applied. has and missing items can have the following fields: type: String - must be...
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
How do I implement Rewriting to an external URL in Next.js?
If you're using trailingSlash: true, you also need to insert a trailing slash in the source parameter. If the destination server is also expecting a trailing slash it should be included in the destination parameter as well. ```javascript module.exports = { async rewrites() { return [ { source: '/blo...
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
3