@@ -25,10 +25,8 @@ Get started in 5 seconds, add this script to your app:
2525
2626Examples:
2727
28- <ul >
29- <li >
3028<details >
31- <summary ><b >Next.js (Pages Router )</b ></summary >
29+ <summary ><b >Next.js (pages )</b ></summary >
3230
3331<br />
3432
@@ -55,11 +53,9 @@ export default function Document() {
5553```
5654
5755</details >
58- </li >
5956
60- <li >
6157<details >
62- <summary ><b >Next.js (App Router )</b ></summary >
58+ <summary ><b >Next.js (app )</b ></summary >
6359
6460<br />
6561
@@ -84,9 +80,7 @@ export default function RootLayout({
8480```
8581
8682</details >
87- </li >
8883
89- <li >
9084<details >
9185<summary ><b >Vite / Create React App</b ></summary >
9286
@@ -109,8 +103,6 @@ Add the script tag to your `index.html`:
109103```
110104
111105</details >
112- </li >
113- </ul >
114106
115107---
116108
@@ -133,45 +125,225 @@ scan({
133125});
134126```
135127
136- ## Examples
128+ ## API Reference
137129
138- If you're digging into performance issues and prefer a more manual approach, use the ` withScan ` API:
130+ <details >
131+ <summary ><code >scan(options)</code ></summary >
139132
140- ``` js
141- import { withScan , setOptions } from ' react-scan' ;
142-
143- const ExpensiveComponent = withScan (
144- (props ) => {
145- // ...
146- },
147- { log: true },
148- );
133+ <br />
134+
135+ Automatically scan your app for renders.
136+
137+ ``` jsx
138+ scan ({
139+ /**
140+ * Enable/disable scanning
141+ */
142+ enabled: true ,
143+ /**
144+ * Include children of a component applied with withScan
145+ */
146+ includeChildren: true ,
147+
148+ /**
149+ * Run in production
150+ */
151+ runInProduction: false ,
152+
153+ /**
154+ * Enable/disable geiger sound
155+ */
156+ playSound: true ,
157+
158+ /**
159+ * Log renders to the console
160+ */
161+ log: false ,
162+
163+ /**
164+ * Show toolbar bar
165+ */
166+ showToolbar: true ,
167+
168+ /**
169+ * Long task threshold in milliseconds, only show
170+ * when main thread is blocked for longer than this
171+ */
172+ longTaskThreshold: 50 ;
173+
174+ /**
175+ * Clear aggregated fibers after this time in milliseconds
176+ */
177+ resetCountTimeout: 5000 ;
178+
179+ onCommitStart?: () => void ;
180+ onRender?: (fiber , render ) => void ;
181+ onCommitFinish?: () => void ;
182+ onPaintStart?: (outline ) => void ;
183+ onPaintFinish?: (outline ) => void ;
184+ })
149185```
150186
151- You can also hook into internal lifecycle methods to for internal data or get a summary of component renders by calling ` getReport() ` :
187+ </ details >
152188
153- ``` js
154- import { setOptions , getReport } from ' react-scan' ;
189+ <details >
190+ <summary ><code >withScan(Component, options)</code ></summary >
191+
192+ <br />
193+
194+ Scan a specific component for renders.
195+
196+ ``` jsx
197+ function Component (props ) {
198+ // ...
199+ }
200+
201+ withScan (Component, {
202+ /**
203+ * Enable/disable scanning
204+ */
205+ enabled: true ,
206+ /**
207+ * Include children of a component applied with withScan
208+ */
209+ includeChildren: true ,
210+
211+ /**
212+ * Run in production
213+ */
214+ runInProduction: false ,
215+
216+ /**
217+ * Enable/disable geiger sound
218+ */
219+ playSound: true ,
220+
221+ /**
222+ * Log renders to the console
223+ */
224+ log: false ,
225+
226+ /**
227+ * Show toolbar bar
228+ */
229+ showToolbar: true ,
230+
231+ /**
232+ * Long task threshold in milliseconds, only show
233+ * when main thread is blocked for longer than this
234+ */
235+ longTaskThreshold: 50 ;
236+
237+ /**
238+ * Clear aggregated fibers after this time in milliseconds
239+ */
240+ resetCountTimeout: 5000 ;
241+
242+ onCommitStart?: () => void ;
243+ onRender?: (fiber , render ) => void ;
244+ onCommitFinish?: () => void ;
245+ onPaintStart?: (outline ) => void ;
246+ onPaintFinish?: (outline ) => void ;
247+ })
248+ ```
249+
250+ </details >
251+
252+ <details >
253+ <summary ><code >getReport()</code ></summary >
254+
255+ <br />
256+
257+ Get a aggregated report of all components and renders.
258+
259+ ``` jsx
260+ const report = getReport ();
261+
262+ for (const component in report) {
263+ const { count , time } = report[component];
264+
265+ console .log (` ${ component} rendered ${ count} times, took ${ time} ms` );
266+ }
267+ ```
268+
269+ </details >
270+
271+ <details >
272+ <summary ><code >setOptions(options)</code ></summary >
273+
274+ ``` jsx
275+ function Component (props ) {
276+ // ...
277+ }
155278
156279setOptions ({
157- onCommitStart () {},
158- onRender (fiber , render ) {},
159- onCommitFinish () {},
160- onPaintStart (outline ) {},
161- onPaintFinish (outline ) {},
162- });
280+ /**
281+ * Enable/disable scanning
282+ */
283+ enabled: true ,
284+ /**
285+ * Include children of a component applied with withScan
286+ */
287+ includeChildren: true ,
288+
289+ /**
290+ * Run in production
291+ */
292+ runInProduction: false ,
293+
294+ /**
295+ * Enable/disable geiger sound
296+ */
297+ playSound: true ,
298+
299+ /**
300+ * Log renders to the console
301+ */
302+ log: false ,
303+
304+ /**
305+ * Show toolbar bar
306+ */
307+ showToolbar: true ,
308+
309+ /**
310+ * Long task threshold in milliseconds, only show
311+ * when main thread is blocked for longer than this
312+ */
313+ longTaskThreshold: 50 ;
314+
315+ /**
316+ * Clear aggregated fibers after this time in milliseconds
317+ */
318+ resetCountTimeout: 5000 ;
319+
320+ onCommitStart?: () => void ;
321+ onRender?: (fiber , render ) => void ;
322+ onCommitFinish?: () => void ;
323+ onPaintStart?: (outline ) => void ;
324+ onPaintFinish?: (outline ) => void ;
325+ })
326+ ```
327+
328+ </details >
329+
330+ <details >
331+ <summary ><code >getOptions()</code ></summary >
163332
164- console .log (getReport ());
165- // ^
166- // {
167- // "ExpensiveComponent": {
168- // count: 100,
169- // time: 400
170- // }
171- // }
333+ ``` jsx
334+ const {
335+ enabled ,
336+ includeChildren ,
337+ runInProduction ,
338+ playSound ,
339+ log ,
340+ showToolbar ,
341+ longTaskThreshold ,
342+ resetCountTimeout ,
343+ } = getOptions ();
172344```
173345
174- And voilà! You're ready to go.
346+ </ details >
175347
176348## Why React Scan?
177349
@@ -244,12 +416,7 @@ We expect all contributors to abide by the terms of our [Code of Conduct](https:
244416- [x] Don't show label if no reconciliation occurred ("client renders" in DevTools)
245417- [x] "global" counter using ` sessionStorage ` , aggregate count stats instead of immediate replacement
246418- [x] Give a general report of the app's performance
247- - [ ] checkbox filtering API, leaderboard
248- - [ ] Offscreen canvas on worker thread
249- - [ ] heatmap decay (stacked renders will be more intense)
250- - [ ] Investigate components (UI allowlist)
251- - [ ] UI for turning on/off options
252- - [ ] "PageSpeed insights" for React
419+
253420- [ ] React Native support
254421- [ ] Name / explain the actual problem, docs
255422- [ ] Simple FPS counter
0 commit comments