Skip to content

Commit c31a011

Browse files
Copilothuangyiirene
andcommitted
fix: Add eslint config for playground and fix lint errors
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 1474d29 commit c31a011

4 files changed

Lines changed: 62 additions & 9 deletions

File tree

apps/playground/eslint.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
export default tseslint.config(
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
},
28+
)

apps/playground/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
"react-dom": "^18.3.1"
2020
},
2121
"devDependencies": {
22+
"@eslint/js": "^9.39.1",
2223
"@types/react": "^18.3.12",
2324
"@types/react-dom": "^18.3.1",
2425
"@vitejs/plugin-react": "^5.1.1",
2526
"autoprefixer": "^10.4.23",
27+
"eslint-plugin-react-hooks": "^7.0.1",
28+
"eslint-plugin-react-refresh": "^0.4.24",
29+
"globals": "^16.5.0",
2630
"postcss": "^8.5.6",
2731
"tailwindcss": "^3.4.19",
2832
"tailwindcss-animate": "^1.0.7",
2933
"typescript": "~5.9.3",
34+
"typescript-eslint": "^8.46.4",
3035
"vite": "^7.2.4"
3136
}
3237
}

apps/playground/src/App.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ type ViewportSize = 'desktop' | 'tablet' | 'mobile';
99
export default function Playground() {
1010
const [selectedExample, setSelectedExample] = useState<ExampleKey>('dashboard');
1111
const [code, setCode] = useState(examples['dashboard']);
12-
const [schema, setSchema] = useState<any>(null);
12+
const [schema, setSchema] = useState<Record<string, unknown> | null>(null);
1313
const [jsonError, setJsonError] = useState<string | null>(null);
1414
const [viewportSize, setViewportSize] = useState<ViewportSize>('desktop');
1515
const [copied, setCopied] = useState(false);
1616

1717
// Real-time JSON parsing
1818
useEffect(() => {
19-
try {
20-
const parsed = JSON.parse(code);
21-
setSchema(parsed);
22-
setJsonError(null);
23-
} catch (e) {
24-
setJsonError((e as Error).message);
25-
// Keep previous schema on error
26-
}
19+
// Parse JSON in a microtask to avoid synchronous setState in effect
20+
const timer = setTimeout(() => {
21+
try {
22+
const parsed = JSON.parse(code);
23+
setSchema(parsed);
24+
setJsonError(null);
25+
} catch (e) {
26+
setJsonError((e as Error).message);
27+
// Keep previous schema on error
28+
}
29+
}, 0);
30+
31+
return () => clearTimeout(timer);
2732
}, [code]);
2833

2934
const handleExampleChange = (key: ExampleKey) => {

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)