Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f56e5c94
Unverified
Commit
f56e5c94
authored
Dec 07, 2022
by
Max Proske
Committed by
GitHub
Dec 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `with-why-did-you-render` example to TypeScript (#43736)
parent
783a3ced
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
38 additions
and
5 deletions
+38
-5
README.md
examples/with-why-did-you-render/README.md
+1
-1
header.tsx
examples/with-why-did-you-render/components/header.tsx
+0
-0
next.config.js
examples/with-why-did-you-render/next.config.js
+4
-2
package.json
examples/with-why-did-you-render/package.json
+5
-1
_app.tsx
examples/with-why-did-you-render/pages/_app.tsx
+6
-0
index.tsx
examples/with-why-did-you-render/pages/index.tsx
+1
-1
wdyr.ts
examples/with-why-did-you-render/scripts/wdyr.ts
+1
-0
tsconfig.json
examples/with-why-did-you-render/tsconfig.json
+20
-0
No files found.
examples/with-why-did-you-render/README.md
View file @
f56e5c94
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
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.
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
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.
js`
at the top of Next.js
`_app.js
`
.
by importing
`wdyr.
ts`
at the top of Next.js
`_app.tsx
`
.
By default, all pure components will be tracked, but you can add
By default, all pure components will be tracked, but you can add
`Component.whyDidYouRender = true`
to regular function components in case you need.
`Component.whyDidYouRender = true`
to regular function components in case you need.
...
...
examples/with-why-did-you-render/components/header.
js
→
examples/with-why-did-you-render/components/header.
tsx
View file @
f56e5c94
File moved
examples/with-why-did-you-render/next.config.js
View file @
f56e5c94
const
path
=
require
(
'path'
)
const
path
=
require
(
'path'
)
/** @type {import('next').NextConfig} */
/** @type {import('next').NextConfig} */
module
.
exports
=
{
const
nextConfig
=
{
webpack
(
config
,
{
dev
,
isServer
})
{
webpack
(
config
,
{
dev
,
isServer
})
{
if
(
dev
&&
!
isServer
)
{
if
(
dev
&&
!
isServer
)
{
const
originalEntry
=
config
.
entry
const
originalEntry
=
config
.
entry
config
.
entry
=
async
()
=>
{
config
.
entry
=
async
()
=>
{
const
wdrPath
=
path
.
resolve
(
__dirname
,
'./scripts/wdyr.
j
s'
)
const
wdrPath
=
path
.
resolve
(
__dirname
,
'./scripts/wdyr.
t
s'
)
const
entries
=
await
originalEntry
()
const
entries
=
await
originalEntry
()
if
(
entries
[
'main.js'
]
&&
!
entries
[
'main.js'
].
includes
(
wdrPath
))
{
if
(
entries
[
'main.js'
]
&&
!
entries
[
'main.js'
].
includes
(
wdrPath
))
{
...
@@ -19,3 +19,5 @@ module.exports = {
...
@@ -19,3 +19,5 @@ module.exports = {
return
config
return
config
},
},
}
}
module
.
exports
=
nextConfig
examples/with-why-did-you-render/package.json
View file @
f56e5c94
...
@@ -11,6 +11,10 @@
...
@@ -11,6 +11,10 @@
"react-dom"
:
"^18.2.0"
"react-dom"
:
"^18.2.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@welldone-software/why-did-you-render"
:
"^7.0.1"
"@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"
}
}
}
}
examples/with-why-did-you-render/pages/_app.
js
→
examples/with-why-did-you-render/pages/_app.
tsx
View file @
f56e5c94
import
{
AppProps
}
from
'next/app'
import
'../scripts/wdyr'
import
'../scripts/wdyr'
export
default
function
App
({
Component
,
pageProps
})
{
export
default
function
App
({
Component
,
pageProps
}
:
AppProps
)
{
return
<
Component
{
...
pageProps
}
/>
return
<
Component
{
...
pageProps
}
/>
}
}
examples/with-why-did-you-render/pages/index.
js
→
examples/with-why-did-you-render/pages/index.
tsx
View file @
f56e5c94
import
Header
from
'../components/header
.js
'
import
Header
from
'../components/header'
export
default
function
Home
()
{
export
default
function
Home
()
{
return
(
return
(
...
...
examples/with-why-did-you-render/scripts/wdyr.
j
s
→
examples/with-why-did-you-render/scripts/wdyr.
t
s
View file @
f56e5c94
/// <reference types="@welldone-software/why-did-you-render" />
import
React
from
'react'
import
React
from
'react'
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
...
...
examples/with-why-did-you-render/tsconfig.json
0 → 100644
View file @
f56e5c94
{
"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"
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment