@kood/claude-code 0.3.12 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/index.js +30 -8
  2. package/package.json +4 -4
  3. package/templates/.claude/skills/korea-uiux-design/SKILL.md +444 -0
  4. package/templates/.claude/skills/korea-uiux-design/references/accessibility.md +298 -0
  5. package/templates/.claude/skills/korea-uiux-design/references/checklist.md +107 -0
  6. package/templates/.claude/skills/korea-uiux-design/references/color-system.md +156 -0
  7. package/templates/.claude/skills/korea-uiux-design/references/design-philosophy.md +25 -0
  8. package/templates/.claude/skills/korea-uiux-design/references/icon-guide.md +180 -0
  9. package/templates/.claude/skills/korea-uiux-design/references/micro-interactions.md +259 -0
  10. package/templates/.claude/skills/korea-uiux-design/references/responsive-patterns.md +115 -0
  11. package/templates/.claude/skills/korea-uiux-design/references/service-patterns.md +206 -0
  12. package/templates/.claude/skills/korea-uiux-design/references/state-patterns.md +320 -0
  13. package/templates/.claude/skills/korea-uiux-design/references/typography.md +70 -0
  14. package/templates/.claude/skills/nextjs-react-best-practices/AGENTS.md +663 -0
  15. package/templates/.claude/skills/nextjs-react-best-practices/SKILL.md +269 -0
  16. package/templates/.claude/skills/tanstack-start-react-best-practices/AGENTS.md +751 -0
  17. package/templates/.claude/skills/tanstack-start-react-best-practices/SKILL.md +431 -0
  18. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-defer-await.md +80 -0
  19. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-dependencies.md +36 -0
  20. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-loader.md +44 -0
  21. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-parallel.md +28 -0
  22. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-barrel-imports.md +59 -0
  23. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-conditional.md +31 -0
  24. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-defer-third-party.md +49 -0
  25. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-lazy-routes.md +67 -0
  26. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-preload.md +50 -0
  27. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-event-listeners.md +74 -0
  28. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-tanstack-query.md +77 -0
  29. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-batch-dom-css.md +82 -0
  30. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-function-results.md +80 -0
  31. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-property-access.md +28 -0
  32. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-storage.md +70 -0
  33. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-combine-iterations.md +32 -0
  34. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-early-exit.md +50 -0
  35. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-hoist-regexp.md +45 -0
  36. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-index-maps.md +37 -0
  37. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-length-check-first.md +49 -0
  38. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-min-max-loop.md +82 -0
  39. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-set-map-lookups.md +24 -0
  40. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-tosorted-immutable.md +57 -0
  41. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  42. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-conditional-render.md +40 -0
  43. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-content-visibility.md +38 -0
  44. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  45. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-svg-precision.md +28 -0
  46. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-defer-reads.md +39 -0
  47. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-dependencies.md +45 -0
  48. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-derived-state.md +29 -0
  49. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-functional-setstate.md +74 -0
  50. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  51. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-memo.md +44 -0
  52. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-transitions.md +40 -0
  53. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-cache-lru.md +41 -0
  54. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-deferred-data.md +67 -0
  55. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-parallel-fetching.md +60 -0
  56. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-serialization.md +38 -0
  57. package/templates/.claude/skills/vercel-react-best-practices/AGENTS.md +0 -2249
  58. package/templates/.claude/skills/vercel-react-best-practices/SKILL.md +0 -125
  59. package/templates/.claude/skills/vs-design-diverge/SKILL.md +0 -307
  60. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/advanced-event-handler-refs.md +0 -0
  61. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/advanced-use-latest.md +0 -0
  62. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/async-api-routes.md +0 -0
  63. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/async-defer-await.md +0 -0
  64. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/async-dependencies.md +0 -0
  65. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/async-parallel.md +0 -0
  66. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/async-suspense-boundaries.md +0 -0
  67. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/bundle-barrel-imports.md +0 -0
  68. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/bundle-conditional.md +0 -0
  69. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/bundle-defer-third-party.md +0 -0
  70. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/bundle-dynamic-imports.md +0 -0
  71. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/bundle-preload.md +0 -0
  72. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/client-event-listeners.md +0 -0
  73. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/client-swr-dedup.md +0 -0
  74. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-batch-dom-css.md +0 -0
  75. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-cache-function-results.md +0 -0
  76. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-cache-property-access.md +0 -0
  77. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-cache-storage.md +0 -0
  78. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-combine-iterations.md +0 -0
  79. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-early-exit.md +0 -0
  80. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-hoist-regexp.md +0 -0
  81. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-index-maps.md +0 -0
  82. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-length-check-first.md +0 -0
  83. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-min-max-loop.md +0 -0
  84. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-set-map-lookups.md +0 -0
  85. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/js-tosorted-immutable.md +0 -0
  86. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-activity.md +0 -0
  87. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-animate-svg-wrapper.md +0 -0
  88. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-conditional-render.md +0 -0
  89. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-content-visibility.md +0 -0
  90. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-hoist-jsx.md +0 -0
  91. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-hydration-no-flicker.md +0 -0
  92. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rendering-svg-precision.md +0 -0
  93. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-defer-reads.md +0 -0
  94. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-dependencies.md +0 -0
  95. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-derived-state.md +0 -0
  96. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-functional-setstate.md +0 -0
  97. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-lazy-state-init.md +0 -0
  98. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-memo.md +0 -0
  99. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/rerender-transitions.md +0 -0
  100. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/server-after-nonblocking.md +0 -0
  101. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/server-cache-lru.md +0 -0
  102. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/server-cache-react.md +0 -0
  103. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/server-parallel-fetching.md +0 -0
  104. /package/templates/.claude/skills/{vercel-react-best-practices → nextjs-react-best-practices}/rules/server-serialization.md +0 -0
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Hoist RegExp Creation
3
+ impact: LOW-MEDIUM
4
+ impactDescription: avoids recreation
5
+ tags: javascript, regexp, optimization, memoization
6
+ ---
7
+
8
+ ## Hoist RegExp Creation
9
+
10
+ Don't create RegExp inside render. Hoist to module scope or memoize with `useMemo()`.
11
+
12
+ **Incorrect (new RegExp every render):**
13
+
14
+ ```tsx
15
+ function Highlighter({ text, query }: Props) {
16
+ const regex = new RegExp(`(${query})`, 'gi')
17
+ const parts = text.split(regex)
18
+ return <>{parts.map((part, i) => ...)}</>
19
+ }
20
+ ```
21
+
22
+ **Correct (memoize or hoist):**
23
+
24
+ ```tsx
25
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
26
+
27
+ function Highlighter({ text, query }: Props) {
28
+ const regex = useMemo(
29
+ () => new RegExp(`(${escapeRegex(query)})`, 'gi'),
30
+ [query]
31
+ )
32
+ const parts = text.split(regex)
33
+ return <>{parts.map((part, i) => ...)}</>
34
+ }
35
+ ```
36
+
37
+ **Warning (global regex has mutable state):**
38
+
39
+ Global regex (`/g`) has mutable `lastIndex` state:
40
+
41
+ ```typescript
42
+ const regex = /foo/g
43
+ regex.test('foo') // true, lastIndex = 3
44
+ regex.test('foo') // false, lastIndex = 0
45
+ ```
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: Build Index Maps for Repeated Lookups
3
+ impact: LOW-MEDIUM
4
+ impactDescription: 1M ops to 2K ops
5
+ tags: javascript, map, indexing, optimization, performance
6
+ ---
7
+
8
+ ## Build Index Maps for Repeated Lookups
9
+
10
+ Multiple `.find()` calls by the same key should use a Map.
11
+
12
+ **Incorrect (O(n) per lookup):**
13
+
14
+ ```typescript
15
+ function processOrders(orders: Order[], users: User[]) {
16
+ return orders.map(order => ({
17
+ ...order,
18
+ user: users.find(u => u.id === order.userId)
19
+ }))
20
+ }
21
+ ```
22
+
23
+ **Correct (O(1) per lookup):**
24
+
25
+ ```typescript
26
+ function processOrders(orders: Order[], users: User[]) {
27
+ const userById = new Map(users.map(u => [u.id, u]))
28
+
29
+ return orders.map(order => ({
30
+ ...order,
31
+ user: userById.get(order.userId)
32
+ }))
33
+ }
34
+ ```
35
+
36
+ Build map once (O(n)), then all lookups are O(1).
37
+ For 1000 orders × 1000 users: 1M ops → 2K ops.
@@ -0,0 +1,49 @@
1
+ ---
2
+ title: Early Length Check for Array Comparisons
3
+ impact: MEDIUM-HIGH
4
+ impactDescription: avoids expensive operations when lengths differ
5
+ tags: javascript, arrays, performance, optimization, comparison
6
+ ---
7
+
8
+ ## Early Length Check for Array Comparisons
9
+
10
+ When comparing arrays with expensive operations (sorting, deep equality, serialization), check lengths first. If lengths differ, the arrays cannot be equal.
11
+
12
+ In real-world applications, this optimization is especially valuable when the comparison runs in hot paths (event handlers, render loops).
13
+
14
+ **Incorrect (always runs expensive comparison):**
15
+
16
+ ```typescript
17
+ function hasChanges(current: string[], original: string[]) {
18
+ // Always sorts and joins, even when lengths differ
19
+ return current.sort().join() !== original.sort().join()
20
+ }
21
+ ```
22
+
23
+ Two O(n log n) sorts run even when `current.length` is 5 and `original.length` is 100. There is also overhead of joining the arrays and comparing the strings.
24
+
25
+ **Correct (O(1) length check first):**
26
+
27
+ ```typescript
28
+ function hasChanges(current: string[], original: string[]) {
29
+ // Early return if lengths differ
30
+ if (current.length !== original.length) {
31
+ return true
32
+ }
33
+ // Only sort/join when lengths match
34
+ const currentSorted = current.toSorted()
35
+ const originalSorted = original.toSorted()
36
+ for (let i = 0; i < currentSorted.length; i++) {
37
+ if (currentSorted[i] !== originalSorted[i]) {
38
+ return true
39
+ }
40
+ }
41
+ return false
42
+ }
43
+ ```
44
+
45
+ This new approach is more efficient because:
46
+ - It avoids the overhead of sorting and joining the arrays when lengths differ
47
+ - It avoids consuming memory for the joined strings (especially important for large arrays)
48
+ - It avoids mutating the original arrays
49
+ - It returns early when a difference is found
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: Use Loop for Min/Max Instead of Sort
3
+ impact: LOW
4
+ impactDescription: O(n) instead of O(n log n)
5
+ tags: javascript, arrays, performance, sorting, algorithms
6
+ ---
7
+
8
+ ## Use Loop for Min/Max Instead of Sort
9
+
10
+ Finding the smallest or largest element only requires a single pass through the array. Sorting is wasteful and slower.
11
+
12
+ **Incorrect (O(n log n) - sort to find latest):**
13
+
14
+ ```typescript
15
+ interface Project {
16
+ id: string
17
+ name: string
18
+ updatedAt: number
19
+ }
20
+
21
+ function getLatestProject(projects: Project[]) {
22
+ const sorted = [...projects].sort((a, b) => b.updatedAt - a.updatedAt)
23
+ return sorted[0]
24
+ }
25
+ ```
26
+
27
+ Sorts the entire array just to find the maximum value.
28
+
29
+ **Incorrect (O(n log n) - sort for oldest and newest):**
30
+
31
+ ```typescript
32
+ function getOldestAndNewest(projects: Project[]) {
33
+ const sorted = [...projects].sort((a, b) => a.updatedAt - b.updatedAt)
34
+ return { oldest: sorted[0], newest: sorted[sorted.length - 1] }
35
+ }
36
+ ```
37
+
38
+ Still sorts unnecessarily when only min/max are needed.
39
+
40
+ **Correct (O(n) - single loop):**
41
+
42
+ ```typescript
43
+ function getLatestProject(projects: Project[]) {
44
+ if (projects.length === 0) return null
45
+
46
+ let latest = projects[0]
47
+
48
+ for (let i = 1; i < projects.length; i++) {
49
+ if (projects[i].updatedAt > latest.updatedAt) {
50
+ latest = projects[i]
51
+ }
52
+ }
53
+
54
+ return latest
55
+ }
56
+
57
+ function getOldestAndNewest(projects: Project[]) {
58
+ if (projects.length === 0) return { oldest: null, newest: null }
59
+
60
+ let oldest = projects[0]
61
+ let newest = projects[0]
62
+
63
+ for (let i = 1; i < projects.length; i++) {
64
+ if (projects[i].updatedAt < oldest.updatedAt) oldest = projects[i]
65
+ if (projects[i].updatedAt > newest.updatedAt) newest = projects[i]
66
+ }
67
+
68
+ return { oldest, newest }
69
+ }
70
+ ```
71
+
72
+ Single pass through the array, no copying, no sorting.
73
+
74
+ **Alternative (Math.min/Math.max for small arrays):**
75
+
76
+ ```typescript
77
+ const numbers = [5, 2, 8, 1, 9]
78
+ const min = Math.min(...numbers)
79
+ const max = Math.max(...numbers)
80
+ ```
81
+
82
+ This works for small arrays but can be slower for very large arrays due to spread operator limitations. Use the loop approach for reliability.
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: Use Set/Map for O(1) Lookups
3
+ impact: LOW-MEDIUM
4
+ impactDescription: O(n) to O(1)
5
+ tags: javascript, set, map, data-structures, performance
6
+ ---
7
+
8
+ ## Use Set/Map for O(1) Lookups
9
+
10
+ Convert arrays to Set/Map for repeated membership checks.
11
+
12
+ **Incorrect (O(n) per check):**
13
+
14
+ ```typescript
15
+ const allowedIds = ['a', 'b', 'c', ...]
16
+ items.filter(item => allowedIds.includes(item.id))
17
+ ```
18
+
19
+ **Correct (O(1) per check):**
20
+
21
+ ```typescript
22
+ const allowedIds = new Set(['a', 'b', 'c', ...])
23
+ items.filter(item => allowedIds.has(item.id))
24
+ ```
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: Use toSorted() Instead of sort() for Immutability
3
+ impact: MEDIUM-HIGH
4
+ impactDescription: prevents mutation bugs in React state
5
+ tags: javascript, arrays, immutability, react, state, mutation
6
+ ---
7
+
8
+ ## Use toSorted() Instead of sort() for Immutability
9
+
10
+ `.sort()` mutates the array in place, which can cause bugs with React state and props. Use `.toSorted()` to create a new sorted array without mutation.
11
+
12
+ **Incorrect (mutates original array):**
13
+
14
+ ```typescript
15
+ function UserList({ users }: { users: User[] }) {
16
+ // Mutates the users prop array!
17
+ const sorted = useMemo(
18
+ () => users.sort((a, b) => a.name.localeCompare(b.name)),
19
+ [users]
20
+ )
21
+ return <div>{sorted.map(renderUser)}</div>
22
+ }
23
+ ```
24
+
25
+ **Correct (creates new array):**
26
+
27
+ ```typescript
28
+ function UserList({ users }: { users: User[] }) {
29
+ // Creates new sorted array, original unchanged
30
+ const sorted = useMemo(
31
+ () => users.toSorted((a, b) => a.name.localeCompare(b.name)),
32
+ [users]
33
+ )
34
+ return <div>{sorted.map(renderUser)}</div>
35
+ }
36
+ ```
37
+
38
+ **Why this matters in React:**
39
+
40
+ 1. Props/state mutations break React's immutability model - React expects props and state to be treated as read-only
41
+ 2. Causes stale closure bugs - Mutating arrays inside closures (callbacks, effects) can lead to unexpected behavior
42
+
43
+ **Browser support (fallback for older browsers):**
44
+
45
+ `.toSorted()` is available in all modern browsers (Chrome 110+, Safari 16+, Firefox 115+, Node.js 20+). For older environments, use spread operator:
46
+
47
+ ```typescript
48
+ // Fallback for older browsers
49
+ const sorted = [...items].sort((a, b) => a.value - b.value)
50
+ ```
51
+
52
+ **Other immutable array methods:**
53
+
54
+ - `.toSorted()` - immutable sort
55
+ - `.toReversed()` - immutable reverse
56
+ - `.toSpliced()` - immutable splice
57
+ - `.with()` - immutable element replacement
@@ -0,0 +1,47 @@
1
+ ---
2
+ title: Animate SVG Wrapper Instead of SVG Element
3
+ impact: LOW
4
+ impactDescription: enables hardware acceleration
5
+ tags: rendering, svg, css, animation, performance
6
+ ---
7
+
8
+ ## Animate SVG Wrapper Instead of SVG Element
9
+
10
+ Many browsers don't have hardware acceleration for CSS3 animations on SVG elements. Wrap SVG in a `<div>` and animate the wrapper instead.
11
+
12
+ **Incorrect (animating SVG directly - no hardware acceleration):**
13
+
14
+ ```tsx
15
+ function LoadingSpinner() {
16
+ return (
17
+ <svg
18
+ className="animate-spin"
19
+ width="24"
20
+ height="24"
21
+ viewBox="0 0 24 24"
22
+ >
23
+ <circle cx="12" cy="12" r="10" stroke="currentColor" />
24
+ </svg>
25
+ )
26
+ }
27
+ ```
28
+
29
+ **Correct (animating wrapper div - hardware accelerated):**
30
+
31
+ ```tsx
32
+ function LoadingSpinner() {
33
+ return (
34
+ <div className="animate-spin">
35
+ <svg
36
+ width="24"
37
+ height="24"
38
+ viewBox="0 0 24 24"
39
+ >
40
+ <circle cx="12" cy="12" r="10" stroke="currentColor" />
41
+ </svg>
42
+ </div>
43
+ )
44
+ }
45
+ ```
46
+
47
+ This applies to all CSS transforms and transitions (`transform`, `opacity`, `translate`, `scale`, `rotate`). The wrapper div allows browsers to use GPU acceleration for smoother animations.
@@ -0,0 +1,40 @@
1
+ ---
2
+ title: Use Explicit Conditional Rendering
3
+ impact: LOW
4
+ impactDescription: prevents rendering 0 or NaN
5
+ tags: rendering, conditional, jsx, falsy-values
6
+ ---
7
+
8
+ ## Use Explicit Conditional Rendering
9
+
10
+ Use explicit ternary operators (`? :`) instead of `&&` for conditional rendering when the condition can be `0`, `NaN`, or other falsy values that render.
11
+
12
+ **Incorrect (renders "0" when count is 0):**
13
+
14
+ ```tsx
15
+ function Badge({ count }: { count: number }) {
16
+ return (
17
+ <div>
18
+ {count && <span className="badge">{count}</span>}
19
+ </div>
20
+ )
21
+ }
22
+
23
+ // When count = 0, renders: <div>0</div>
24
+ // When count = 5, renders: <div><span class="badge">5</span></div>
25
+ ```
26
+
27
+ **Correct (renders nothing when count is 0):**
28
+
29
+ ```tsx
30
+ function Badge({ count }: { count: number }) {
31
+ return (
32
+ <div>
33
+ {count > 0 ? <span className="badge">{count}</span> : null}
34
+ </div>
35
+ )
36
+ }
37
+
38
+ // When count = 0, renders: <div></div>
39
+ // When count = 5, renders: <div><span class="badge">5</span></div>
40
+ ```
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: CSS content-visibility for Long Lists
3
+ impact: HIGH
4
+ impactDescription: faster initial render
5
+ tags: rendering, css, content-visibility, long-lists
6
+ ---
7
+
8
+ ## CSS content-visibility for Long Lists
9
+
10
+ Apply `content-visibility: auto` to defer off-screen rendering.
11
+
12
+ **CSS:**
13
+
14
+ ```css
15
+ .message-item {
16
+ content-visibility: auto;
17
+ contain-intrinsic-size: 0 80px;
18
+ }
19
+ ```
20
+
21
+ **Example:**
22
+
23
+ ```tsx
24
+ function MessageList({ messages }: { messages: Message[] }) {
25
+ return (
26
+ <div className="overflow-y-auto h-screen">
27
+ {messages.map(msg => (
28
+ <div key={msg.id} className="message-item">
29
+ <Avatar user={msg.author} />
30
+ <div>{msg.content}</div>
31
+ </div>
32
+ ))}
33
+ </div>
34
+ )
35
+ }
36
+ ```
37
+
38
+ For 1000 messages, browser skips layout/paint for ~990 off-screen items (10× faster initial render).
@@ -0,0 +1,46 @@
1
+ ---
2
+ title: Hoist Static JSX Elements
3
+ impact: LOW
4
+ impactDescription: avoids re-creation
5
+ tags: rendering, jsx, static, optimization
6
+ ---
7
+
8
+ ## Hoist Static JSX Elements
9
+
10
+ Extract static JSX outside components to avoid re-creation.
11
+
12
+ **Incorrect (recreates element every render):**
13
+
14
+ ```tsx
15
+ function LoadingSkeleton() {
16
+ return <div className="animate-pulse h-20 bg-gray-200" />
17
+ }
18
+
19
+ function Container() {
20
+ return (
21
+ <div>
22
+ {loading && <LoadingSkeleton />}
23
+ </div>
24
+ )
25
+ }
26
+ ```
27
+
28
+ **Correct (reuses same element):**
29
+
30
+ ```tsx
31
+ const loadingSkeleton = (
32
+ <div className="animate-pulse h-20 bg-gray-200" />
33
+ )
34
+
35
+ function Container() {
36
+ return (
37
+ <div>
38
+ {loading && loadingSkeleton}
39
+ </div>
40
+ )
41
+ }
42
+ ```
43
+
44
+ This is especially helpful for large and static SVG nodes, which can be expensive to recreate on every render.
45
+
46
+ **Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, the compiler automatically hoists static JSX elements and optimizes component re-renders, making manual hoisting unnecessary.
@@ -0,0 +1,28 @@
1
+ ---
2
+ title: Optimize SVG Precision
3
+ impact: LOW
4
+ impactDescription: reduces file size
5
+ tags: rendering, svg, optimization, svgo
6
+ ---
7
+
8
+ ## Optimize SVG Precision
9
+
10
+ Reduce SVG coordinate precision to decrease file size. The optimal precision depends on the viewBox size, but in general reducing precision should be considered.
11
+
12
+ **Incorrect (excessive precision):**
13
+
14
+ ```svg
15
+ <path d="M 10.293847 20.847362 L 30.938472 40.192837" />
16
+ ```
17
+
18
+ **Correct (1 decimal place):**
19
+
20
+ ```svg
21
+ <path d="M 10.3 20.8 L 30.9 40.2" />
22
+ ```
23
+
24
+ **Automate with SVGO:**
25
+
26
+ ```bash
27
+ npx svgo --precision=1 --multipass icon.svg
28
+ ```
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: Defer State Reads to Usage Point
3
+ impact: MEDIUM
4
+ impactDescription: avoids unnecessary subscriptions
5
+ tags: rerender, searchParams, localStorage, optimization
6
+ ---
7
+
8
+ ## Defer State Reads to Usage Point
9
+
10
+ Don't subscribe to dynamic state (searchParams, localStorage) if you only read it inside callbacks.
11
+
12
+ **Incorrect (subscribes to all searchParams changes):**
13
+
14
+ ```tsx
15
+ function ShareButton({ chatId }: { chatId: string }) {
16
+ const searchParams = useSearchParams()
17
+
18
+ const handleShare = () => {
19
+ const ref = searchParams.get('ref')
20
+ shareChat(chatId, { ref })
21
+ }
22
+
23
+ return <button onClick={handleShare}>Share</button>
24
+ }
25
+ ```
26
+
27
+ **Correct (reads on demand, no subscription):**
28
+
29
+ ```tsx
30
+ function ShareButton({ chatId }: { chatId: string }) {
31
+ const handleShare = () => {
32
+ const params = new URLSearchParams(window.location.search)
33
+ const ref = params.get('ref')
34
+ shareChat(chatId, { ref })
35
+ }
36
+
37
+ return <button onClick={handleShare}>Share</button>
38
+ }
39
+ ```
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Narrow Effect Dependencies
3
+ impact: LOW
4
+ impactDescription: minimizes effect re-runs
5
+ tags: rerender, useEffect, dependencies, optimization
6
+ ---
7
+
8
+ ## Narrow Effect Dependencies
9
+
10
+ Specify primitive dependencies instead of objects to minimize effect re-runs.
11
+
12
+ **Incorrect (re-runs on any user field change):**
13
+
14
+ ```tsx
15
+ useEffect(() => {
16
+ console.log(user.id)
17
+ }, [user])
18
+ ```
19
+
20
+ **Correct (re-runs only when id changes):**
21
+
22
+ ```tsx
23
+ useEffect(() => {
24
+ console.log(user.id)
25
+ }, [user.id])
26
+ ```
27
+
28
+ **For derived state, compute outside effect:**
29
+
30
+ ```tsx
31
+ // Incorrect: runs on width=767, 766, 765...
32
+ useEffect(() => {
33
+ if (width < 768) {
34
+ enableMobileMode()
35
+ }
36
+ }, [width])
37
+
38
+ // Correct: runs only on boolean transition
39
+ const isMobile = width < 768
40
+ useEffect(() => {
41
+ if (isMobile) {
42
+ enableMobileMode()
43
+ }
44
+ }, [isMobile])
45
+ ```
@@ -0,0 +1,29 @@
1
+ ---
2
+ title: Subscribe to Derived State
3
+ impact: MEDIUM
4
+ impactDescription: reduces re-render frequency
5
+ tags: rerender, derived-state, media-query, optimization
6
+ ---
7
+
8
+ ## Subscribe to Derived State
9
+
10
+ Subscribe to derived boolean state instead of continuous values to reduce re-render frequency.
11
+
12
+ **Incorrect (re-renders on every pixel change):**
13
+
14
+ ```tsx
15
+ function Sidebar() {
16
+ const width = useWindowWidth() // updates continuously
17
+ const isMobile = width < 768
18
+ return <nav className={isMobile ? 'mobile' : 'desktop'}>
19
+ }
20
+ ```
21
+
22
+ **Correct (re-renders only when boolean changes):**
23
+
24
+ ```tsx
25
+ function Sidebar() {
26
+ const isMobile = useMediaQuery('(max-width: 767px)')
27
+ return <nav className={isMobile ? 'mobile' : 'desktop'}>
28
+ }
29
+ ```
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: Use Functional setState Updates
3
+ impact: MEDIUM
4
+ impactDescription: prevents stale closures and unnecessary callback recreations
5
+ tags: react, hooks, useState, useCallback, callbacks, closures
6
+ ---
7
+
8
+ ## Use Functional setState Updates
9
+
10
+ When updating state based on the current state value, use the functional update form of setState instead of directly referencing the state variable. This prevents stale closures, eliminates unnecessary dependencies, and creates stable callback references.
11
+
12
+ **Incorrect (requires state as dependency):**
13
+
14
+ ```tsx
15
+ function TodoList() {
16
+ const [items, setItems] = useState(initialItems)
17
+
18
+ // Callback must depend on items, recreated on every items change
19
+ const addItems = useCallback((newItems: Item[]) => {
20
+ setItems([...items, ...newItems])
21
+ }, [items]) // ❌ items dependency causes recreations
22
+
23
+ // Risk of stale closure if dependency is forgotten
24
+ const removeItem = useCallback((id: string) => {
25
+ setItems(items.filter(item => item.id !== id))
26
+ }, []) // ❌ Missing items dependency - will use stale items!
27
+
28
+ return <ItemsEditor items={items} onAdd={addItems} onRemove={removeItem} />
29
+ }
30
+ ```
31
+
32
+ The first callback is recreated every time `items` changes, which can cause child components to re-render unnecessarily. The second callback has a stale closure bug—it will always reference the initial `items` value.
33
+
34
+ **Correct (stable callbacks, no stale closures):**
35
+
36
+ ```tsx
37
+ function TodoList() {
38
+ const [items, setItems] = useState(initialItems)
39
+
40
+ // Stable callback, never recreated
41
+ const addItems = useCallback((newItems: Item[]) => {
42
+ setItems(curr => [...curr, ...newItems])
43
+ }, []) // ✅ No dependencies needed
44
+
45
+ // Always uses latest state, no stale closure risk
46
+ const removeItem = useCallback((id: string) => {
47
+ setItems(curr => curr.filter(item => item.id !== id))
48
+ }, []) // ✅ Safe and stable
49
+
50
+ return <ItemsEditor items={items} onAdd={addItems} onRemove={removeItem} />
51
+ }
52
+ ```
53
+
54
+ **Benefits:**
55
+
56
+ 1. **Stable callback references** - Callbacks don't need to be recreated when state changes
57
+ 2. **No stale closures** - Always operates on the latest state value
58
+ 3. **Fewer dependencies** - Simplifies dependency arrays and reduces memory leaks
59
+ 4. **Prevents bugs** - Eliminates the most common source of React closure bugs
60
+
61
+ **When to use functional updates:**
62
+
63
+ - Any setState that depends on the current state value
64
+ - Inside useCallback/useMemo when state is needed
65
+ - Event handlers that reference state
66
+ - Async operations that update state
67
+
68
+ **When direct updates are fine:**
69
+
70
+ - Setting state to a static value: `setCount(0)`
71
+ - Setting state from props/arguments only: `setName(newName)`
72
+ - State doesn't depend on previous value
73
+
74
+ **Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, the compiler can automatically optimize some cases, but functional updates are still recommended for correctness and to prevent stale closure bugs.