Skip to content

Commit 3af19c8

Browse files
committed
Add @react-scan/component
1 parent ec547fd commit 3af19c8

File tree

7 files changed

+842
-27
lines changed

7 files changed

+842
-27
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"scripts": {
55
"build": "WORKSPACE_BUILD=true node scripts/workspace.mjs build",
66
"postbuild": "node scripts/version-warning.mjs",
7-
"postinstall": "pnpm build",
87
"dev": "node scripts/workspace.mjs dev",
98
"pack": "node scripts/workspace.mjs pack",
109
"pack:bump": "pnpm --filter scan pack:bump",

packages/component/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `@react-scan/component`
2+
3+
## Install
4+
5+
```bash
6+
npm i react-scan @react-scan/component
7+
```
8+
9+
```bash
10+
pnpm add react-scan @react-scan/component
11+
```
12+
13+
## Usage
14+
15+
```jsx
16+
import { ReactScan } from "@react-scan/component";
17+
18+
export default function App() {
19+
return (
20+
<>
21+
<ReactScan enabled />
22+
</>
23+
);
24+
}
25+
```

packages/component/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@react-scan/component",
3+
"type": "module",
4+
"scripts": {
5+
"build": "vite build"
6+
},
7+
"peerDependencies": {
8+
"react": ">=16.9",
9+
"react-scan": "^0.1"
10+
},
11+
"devDependencies": {
12+
"@types/react": "^19.0.8",
13+
"@vitejs/plugin-react": "^4.3.4",
14+
"react": "^19.0.0",
15+
"react-scan": "^0.1.1",
16+
"rollup-preserve-directives": "^1.1.3",
17+
"vite": "^6.0.11",
18+
"vite-plugin-dts": "^4.5.0"
19+
},
20+
"exports": {
21+
"types": "./dist/react-scan-component.d.ts",
22+
"import": "./dist/react-scan-component.js",
23+
"require": "./dist/react-scan-component.cjs",
24+
"default": "./dist/react-scan-component.cjs"
25+
}
26+
}

packages/component/src/index.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use client';
2+
import { JSX, useEffect } from 'react';
3+
import { Options, Store, scan } from 'react-scan';
4+
5+
export interface ReactScanProps extends Options {
6+
isInIFrame?: boolean;
7+
}
8+
9+
export function ReactScan({
10+
isInIFrame,
11+
enabled,
12+
dangerouslyForceRunInProduction,
13+
log,
14+
showToolbar,
15+
animationSpeed,
16+
trackUnnecessaryRenders,
17+
onCommitFinish,
18+
onCommitStart,
19+
onPaintFinish,
20+
onPaintStart,
21+
onRender,
22+
}: ReactScanProps): JSX.Element {
23+
useEffect(() => {
24+
Store.isInIframe.value = !!isInIFrame;
25+
}, [isInIFrame]);
26+
27+
useEffect(() => {
28+
if (!enabled) {
29+
return;
30+
}
31+
scan({
32+
enabled,
33+
dangerouslyForceRunInProduction,
34+
log,
35+
showToolbar,
36+
animationSpeed,
37+
trackUnnecessaryRenders,
38+
onCommitFinish,
39+
onCommitStart,
40+
onPaintFinish,
41+
onPaintStart,
42+
onRender,
43+
});
44+
return () => {
45+
scan({ enabled: false });
46+
};
47+
}, [
48+
enabled,
49+
dangerouslyForceRunInProduction,
50+
log,
51+
showToolbar,
52+
animationSpeed,
53+
trackUnnecessaryRenders,
54+
onCommitFinish,
55+
onCommitStart,
56+
onPaintFinish,
57+
onPaintStart,
58+
onRender,
59+
]);
60+
return <></>;
61+
}

packages/component/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"exclude": ["node_modules"],
3+
"include": ["src", "types", "test"],
4+
"compilerOptions": {
5+
"module": "ESNext",
6+
"lib": ["ESNext", "DOM"],
7+
"importHelpers": true,
8+
"declaration": true,
9+
"sourceMap": true,
10+
"rootDir": "./src",
11+
"strict": true,
12+
"types": ["vite/client"],
13+
"noUnusedLocals": true,
14+
"noUnusedParameters": true,
15+
"noImplicitReturns": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"moduleResolution": "bundler",
18+
"jsx": "react-jsx",
19+
"jsxImportSource": "react",
20+
"esModuleInterop": true,
21+
"target": "ESNext",
22+
"useDefineForClassFields": false,
23+
"declarationMap": true
24+
}
25+
}

packages/component/vite.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import react from '@vitejs/plugin-react';
2+
import { dirname, resolve } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import preserveDirectives from 'rollup-preserve-directives';
5+
import { defineConfig } from 'vite';
6+
import dts from 'vite-plugin-dts';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
10+
export default defineConfig({
11+
build: {
12+
lib: {
13+
entry: resolve(__dirname, 'src/index.tsx'),
14+
name: 'ReactScan',
15+
// the proper extensions will be added
16+
fileName: 'react-scan-component',
17+
formats: ['es', 'cjs'],
18+
},
19+
rollupOptions: {
20+
external: ['react', 'react-scan', 'react/jsx-runtime'],
21+
},
22+
},
23+
plugins: [
24+
preserveDirectives(),
25+
react(),
26+
dts({
27+
insertTypesEntry: true,
28+
}),
29+
],
30+
});

0 commit comments

Comments
 (0)