docs/installation/next-js-page-router.md
Add the script tag to your pages/_document
Refer to the CDN Guide for the available URLs.
// pages/_document
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head>
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
Add the following code to your App component in pages/_app:
// pages/_app
// react-scan must be the top-most import
import { scan } from "react-scan";
import { useEffect } from "react";
export default function App({ Component, pageProps }) {
useEffect(() => {
// Make sure to run React Scan after hydration
scan({
enabled: true,
});
}, []);
return <Component {...pageProps} />;
}
If you want react-scan to also run in production, use the react-scan/all-environments import path
- import { scan } from "react-scan";
+ import { scan } from "react-scan/all-environments";