Unverified Commit 41d890aa authored by Lee Robinson's avatar Lee Robinson Committed by GitHub

examples: Remove outdated example (#58568)

Closes https://github.com/vercel/next.js/issues/54309.
parent d115ccad
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# 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
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
# Why did you render
This is a simple example of how to use [why-did-you-render](https://github.com/welldone-software/why-did-you-render) within a Next.js app.
We are essentially extending webpack config to allow the monkey patched `React` version of WDYR in development mode and adding to our application
by importing `wdyr.ts` at the top of Next.js `_app.tsx`.
By default, all pure components will be tracked, but you can add
`Component.whyDidYouRender = true` to regular function components in case you need.
In this example, the header component will rerender despite the state staying the same.
You can see `why-did-you-render` console logs about this redundant re-render in the developer console.
When using Typescript, call the file `wdyr.ts` instead and add the following line to the top of the file to import the package's types:
```
/// <reference types="@welldone-software/why-did-you-render" />
```
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-why-did-you-render)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-why-did-you-render&project-name=with-why-did-you-render&repository-name=with-why-did-you-render)
## 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/), or [pnpm](https://pnpm.io) to bootstrap the example:
```bash
npx create-next-app --example with-why-did-you-render with-why-did-you-render-app
```
```bash
yarn create next-app --example with-why-did-you-render with-why-did-you-render-app
```
```bash
pnpm create next-app --example with-why-did-you-render with-why-did-you-render-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/new?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
import { useState, useEffect } from 'react'
const Header = () => {
const [objState, setObjState] = useState({ name: 'World' })
useEffect(() => {
setObjState({ name: 'World' })
}, [])
return (
<header>
<h1>Hello {objState.name} !</h1>
</header>
)
}
Header.whyDidYouRender = true
export default Header
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
const path = require('path')
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config, { dev, isServer }) {
if (dev && !isServer) {
const originalEntry = config.entry
config.entry = async () => {
const wdrPath = path.resolve(__dirname, './scripts/wdyr.ts')
const entries = await originalEntry()
if (entries['main.js'] && !entries['main.js'].includes(wdrPath)) {
entries['main.js'].push(wdrPath)
}
return entries
}
}
return config
},
}
module.exports = nextConfig
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.10",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@welldone-software/why-did-you-render": "^7.0.1",
"typescript": "^4.9.3"
}
}
import { AppProps } from 'next/app'
import '../scripts/wdyr'
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
import Header from '../components/header'
export default function Home() {
return (
<div>
<Header />
</div>
)
}
/// <reference types="@welldone-software/why-did-you-render" />
import React from 'react'
if (process.env.NODE_ENV === 'development') {
if (typeof window !== 'undefined') {
const whyDidYouRender = require('@welldone-software/why-did-you-render')
whyDidYouRender(React, {
trackAllPureComponents: true,
})
}
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment