@0xsown/vibe-code-fe 1.0.0
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.
- package/bin/index.js +181 -0
- package/package.json +32 -0
- package/skills/claude-md-improver/SKILL.md +179 -0
- package/skills/claude-md-improver/references/quality-criteria.md +109 -0
- package/skills/claude-md-improver/references/templates.md +253 -0
- package/skills/claude-md-improver/references/update-guidelines.md +150 -0
- package/skills/find-skills/SKILL.md +133 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +42 -0
- package/skills/next-best-practices/SKILL.md +153 -0
- package/skills/next-best-practices/async-patterns.md +87 -0
- package/skills/next-best-practices/bundling.md +180 -0
- package/skills/next-best-practices/data-patterns.md +297 -0
- package/skills/next-best-practices/debug-tricks.md +105 -0
- package/skills/next-best-practices/directives.md +73 -0
- package/skills/next-best-practices/error-handling.md +227 -0
- package/skills/next-best-practices/file-conventions.md +140 -0
- package/skills/next-best-practices/font.md +245 -0
- package/skills/next-best-practices/functions.md +108 -0
- package/skills/next-best-practices/hydration-error.md +91 -0
- package/skills/next-best-practices/image.md +173 -0
- package/skills/next-best-practices/metadata.md +301 -0
- package/skills/next-best-practices/parallel-routes.md +287 -0
- package/skills/next-best-practices/route-handlers.md +146 -0
- package/skills/next-best-practices/rsc-boundaries.md +159 -0
- package/skills/next-best-practices/runtime-selection.md +39 -0
- package/skills/next-best-practices/scripts.md +141 -0
- package/skills/next-best-practices/self-hosting.md +371 -0
- package/skills/next-best-practices/suspense-boundaries.md +67 -0
- package/skills/next-cache-components/SKILL.md +411 -0
- package/skills/shadcn-ui/README.md +248 -0
- package/skills/shadcn-ui/SKILL.md +326 -0
- package/skills/shadcn-ui/examples/auth-layout.tsx +177 -0
- package/skills/shadcn-ui/examples/data-table.tsx +313 -0
- package/skills/shadcn-ui/examples/form-pattern.tsx +177 -0
- package/skills/shadcn-ui/resources/component-catalog.md +481 -0
- package/skills/shadcn-ui/resources/customization-guide.md +516 -0
- package/skills/shadcn-ui/resources/migration-guide.md +463 -0
- package/skills/shadcn-ui/resources/setup-guide.md +412 -0
- package/skills/shadcn-ui/scripts/verify-setup.sh +134 -0
- package/skills/supabase-postgres-best-practices/AGENTS.md +68 -0
- package/skills/supabase-postgres-best-practices/CLAUDE.md +68 -0
- package/skills/supabase-postgres-best-practices/README.md +116 -0
- package/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/skills/supabase-postgres-best-practices/references/security-rls-performance.md +57 -0
- package/skills/tailwind-design-system/SKILL.md +874 -0
- package/skills/vercel-composition-patterns/AGENTS.md +946 -0
- package/skills/vercel-composition-patterns/README.md +60 -0
- package/skills/vercel-composition-patterns/SKILL.md +89 -0
- package/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
- package/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
- package/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
- package/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
- package/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
- package/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
- package/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
- package/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
- package/skills/vercel-react-best-practices/AGENTS.md +2934 -0
- package/skills/vercel-react-best-practices/README.md +123 -0
- package/skills/vercel-react-best-practices/SKILL.md +136 -0
- package/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/skills/vercel-react-best-practices/rules/async-defer-await.md +80 -0
- package/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/skills/vercel-react-native-skills/AGENTS.md +2897 -0
- package/skills/vercel-react-native-skills/README.md +165 -0
- package/skills/vercel-react-native-skills/SKILL.md +121 -0
- package/skills/vercel-react-native-skills/rules/animation-derived-value.md +53 -0
- package/skills/vercel-react-native-skills/rules/animation-gesture-detector-press.md +95 -0
- package/skills/vercel-react-native-skills/rules/animation-gpu-properties.md +65 -0
- package/skills/vercel-react-native-skills/rules/design-system-compound-components.md +66 -0
- package/skills/vercel-react-native-skills/rules/fonts-config-plugin.md +71 -0
- package/skills/vercel-react-native-skills/rules/imports-design-system-folder.md +68 -0
- package/skills/vercel-react-native-skills/rules/js-hoist-intl.md +61 -0
- package/skills/vercel-react-native-skills/rules/list-performance-callbacks.md +44 -0
- package/skills/vercel-react-native-skills/rules/list-performance-function-references.md +132 -0
- package/skills/vercel-react-native-skills/rules/list-performance-images.md +53 -0
- package/skills/vercel-react-native-skills/rules/list-performance-inline-objects.md +97 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-expensive.md +94 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-memo.md +82 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-types.md +104 -0
- package/skills/vercel-react-native-skills/rules/list-performance-virtualize.md +67 -0
- package/skills/vercel-react-native-skills/rules/monorepo-native-deps-in-app.md +46 -0
- package/skills/vercel-react-native-skills/rules/monorepo-single-dependency-versions.md +63 -0
- package/skills/vercel-react-native-skills/rules/navigation-native-navigators.md +188 -0
- package/skills/vercel-react-native-skills/rules/react-compiler-destructure-functions.md +50 -0
- package/skills/vercel-react-native-skills/rules/react-compiler-reanimated-shared-values.md +48 -0
- package/skills/vercel-react-native-skills/rules/react-state-dispatcher.md +91 -0
- package/skills/vercel-react-native-skills/rules/react-state-fallback.md +56 -0
- package/skills/vercel-react-native-skills/rules/react-state-minimize.md +65 -0
- package/skills/vercel-react-native-skills/rules/rendering-no-falsy-and.md +74 -0
- package/skills/vercel-react-native-skills/rules/rendering-text-in-text-component.md +36 -0
- package/skills/vercel-react-native-skills/rules/scroll-position-no-state.md +82 -0
- package/skills/vercel-react-native-skills/rules/state-ground-truth.md +80 -0
- package/skills/vercel-react-native-skills/rules/ui-expo-image.md +66 -0
- package/skills/vercel-react-native-skills/rules/ui-image-gallery.md +104 -0
- package/skills/vercel-react-native-skills/rules/ui-measure-views.md +78 -0
- package/skills/vercel-react-native-skills/rules/ui-menus.md +174 -0
- package/skills/vercel-react-native-skills/rules/ui-native-modals.md +77 -0
- package/skills/vercel-react-native-skills/rules/ui-pressable.md +61 -0
- package/skills/vercel-react-native-skills/rules/ui-safe-area-scroll.md +65 -0
- package/skills/vercel-react-native-skills/rules/ui-scrollview-content-inset.md +45 -0
- package/skills/vercel-react-native-skills/rules/ui-styling.md +87 -0
- package/skills/web-design-guidelines/SKILL.md +39 -0
- package/templates/AGENTS.md +31 -0
- package/templates/CLAUDE.md +31 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# React Native Guidelines
|
|
2
|
+
|
|
3
|
+
A structured repository for creating and maintaining React Native Best Practices
|
|
4
|
+
optimized for agents and LLMs.
|
|
5
|
+
|
|
6
|
+
## Structure
|
|
7
|
+
|
|
8
|
+
- `rules/` - Individual rule files (one per rule)
|
|
9
|
+
- `_sections.md` - Section metadata (titles, impacts, descriptions)
|
|
10
|
+
- `_template.md` - Template for creating new rules
|
|
11
|
+
- `area-description.md` - Individual rule files
|
|
12
|
+
- `metadata.json` - Document metadata (version, organization, abstract)
|
|
13
|
+
- **`AGENTS.md`** - Compiled output (generated)
|
|
14
|
+
|
|
15
|
+
## Rules
|
|
16
|
+
|
|
17
|
+
### Core Rendering (CRITICAL)
|
|
18
|
+
|
|
19
|
+
- `rendering-text-in-text-component.md` - Wrap strings in Text components
|
|
20
|
+
- `rendering-no-falsy-and.md` - Avoid falsy && operator in JSX
|
|
21
|
+
|
|
22
|
+
### List Performance (HIGH)
|
|
23
|
+
|
|
24
|
+
- `list-performance-virtualize.md` - Use virtualized lists (LegendList,
|
|
25
|
+
FlashList)
|
|
26
|
+
- `list-performance-function-references.md` - Keep stable object references
|
|
27
|
+
- `list-performance-callbacks.md` - Hoist callbacks to list root
|
|
28
|
+
- `list-performance-inline-objects.md` - Avoid inline objects in renderItem
|
|
29
|
+
- `list-performance-item-memo.md` - Pass primitives for memoization
|
|
30
|
+
- `list-performance-item-expensive.md` - Keep list items lightweight
|
|
31
|
+
- `list-performance-images.md` - Use compressed images in lists
|
|
32
|
+
- `list-performance-item-types.md` - Use item types for heterogeneous lists
|
|
33
|
+
|
|
34
|
+
### Animation (HIGH)
|
|
35
|
+
|
|
36
|
+
- `animation-gpu-properties.md` - Animate transform/opacity instead of layout
|
|
37
|
+
- `animation-gesture-detector-press.md` - Use GestureDetector for press
|
|
38
|
+
animations
|
|
39
|
+
- `animation-derived-value.md` - Prefer useDerivedValue over useAnimatedReaction
|
|
40
|
+
|
|
41
|
+
### Scroll Performance (HIGH)
|
|
42
|
+
|
|
43
|
+
- `scroll-position-no-state.md` - Never track scroll in useState
|
|
44
|
+
|
|
45
|
+
### Navigation (HIGH)
|
|
46
|
+
|
|
47
|
+
- `navigation-native-navigators.md` - Use native stack and native tabs
|
|
48
|
+
|
|
49
|
+
### React State (MEDIUM)
|
|
50
|
+
|
|
51
|
+
- `react-state-dispatcher.md` - Use functional setState updates
|
|
52
|
+
- `react-state-fallback.md` - State should represent user intent only
|
|
53
|
+
- `react-state-minimize.md` - Minimize state variables, derive values
|
|
54
|
+
|
|
55
|
+
### State Architecture (MEDIUM)
|
|
56
|
+
|
|
57
|
+
- `state-ground-truth.md` - State must represent ground truth
|
|
58
|
+
|
|
59
|
+
### React Compiler (MEDIUM)
|
|
60
|
+
|
|
61
|
+
- `react-compiler-destructure-functions.md` - Destructure functions early
|
|
62
|
+
- `react-compiler-reanimated-shared-values.md` - Use .get()/.set() for shared
|
|
63
|
+
values
|
|
64
|
+
|
|
65
|
+
### User Interface (MEDIUM)
|
|
66
|
+
|
|
67
|
+
- `ui-expo-image.md` - Use expo-image for optimized images
|
|
68
|
+
- `ui-image-gallery.md` - Use Galeria for lightbox/galleries
|
|
69
|
+
- `ui-menus.md` - Native dropdown and context menus with Zeego
|
|
70
|
+
- `ui-native-modals.md` - Use native Modal with formSheet
|
|
71
|
+
- `ui-pressable.md` - Use Pressable instead of TouchableOpacity
|
|
72
|
+
- `ui-measure-views.md` - Measuring view dimensions
|
|
73
|
+
- `ui-safe-area-scroll.md` - Use contentInsetAdjustmentBehavior
|
|
74
|
+
- `ui-scrollview-content-inset.md` - Use contentInset for dynamic spacing
|
|
75
|
+
- `ui-styling.md` - Modern styling patterns (gap, boxShadow, gradients)
|
|
76
|
+
|
|
77
|
+
### Design System (MEDIUM)
|
|
78
|
+
|
|
79
|
+
- `design-system-compound-components.md` - Use compound components
|
|
80
|
+
|
|
81
|
+
### Monorepo (LOW)
|
|
82
|
+
|
|
83
|
+
- `monorepo-native-deps-in-app.md` - Install native deps in app directory
|
|
84
|
+
- `monorepo-single-dependency-versions.md` - Single dependency versions
|
|
85
|
+
|
|
86
|
+
### Third-Party Dependencies (LOW)
|
|
87
|
+
|
|
88
|
+
- `imports-design-system-folder.md` - Import from design system folder
|
|
89
|
+
|
|
90
|
+
### JavaScript (LOW)
|
|
91
|
+
|
|
92
|
+
- `js-hoist-intl.md` - Hoist Intl formatter creation
|
|
93
|
+
|
|
94
|
+
### Fonts (LOW)
|
|
95
|
+
|
|
96
|
+
- `fonts-config-plugin.md` - Load fonts natively at build time
|
|
97
|
+
|
|
98
|
+
## Creating a New Rule
|
|
99
|
+
|
|
100
|
+
1. Copy `rules/_template.md` to `rules/area-description.md`
|
|
101
|
+
2. Choose the appropriate area prefix:
|
|
102
|
+
- `rendering-` for Core Rendering
|
|
103
|
+
- `list-performance-` for List Performance
|
|
104
|
+
- `animation-` for Animation
|
|
105
|
+
- `scroll-` for Scroll Performance
|
|
106
|
+
- `navigation-` for Navigation
|
|
107
|
+
- `react-state-` for React State
|
|
108
|
+
- `state-` for State Architecture
|
|
109
|
+
- `react-compiler-` for React Compiler
|
|
110
|
+
- `ui-` for User Interface
|
|
111
|
+
- `design-system-` for Design System
|
|
112
|
+
- `monorepo-` for Monorepo
|
|
113
|
+
- `imports-` for Third-Party Dependencies
|
|
114
|
+
- `js-` for JavaScript
|
|
115
|
+
- `fonts-` for Fonts
|
|
116
|
+
3. Fill in the frontmatter and content
|
|
117
|
+
4. Ensure you have clear examples with explanations
|
|
118
|
+
|
|
119
|
+
## Rule File Structure
|
|
120
|
+
|
|
121
|
+
Each rule file should follow this structure:
|
|
122
|
+
|
|
123
|
+
````markdown
|
|
124
|
+
---
|
|
125
|
+
title: Rule Title Here
|
|
126
|
+
impact: MEDIUM
|
|
127
|
+
impactDescription: Optional description
|
|
128
|
+
tags: tag1, tag2, tag3
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Rule Title Here
|
|
132
|
+
|
|
133
|
+
Brief explanation of the rule and why it matters.
|
|
134
|
+
|
|
135
|
+
**Incorrect (description of what's wrong):**
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
// Bad code example
|
|
139
|
+
```
|
|
140
|
+
````
|
|
141
|
+
|
|
142
|
+
**Correct (description of what's right):**
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
// Good code example
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Reference: [Link](https://example.com)
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## File Naming Convention
|
|
153
|
+
|
|
154
|
+
- Files starting with `_` are special (excluded from build)
|
|
155
|
+
- Rule files: `area-description.md` (e.g., `animation-gpu-properties.md`)
|
|
156
|
+
- Section is automatically inferred from filename prefix
|
|
157
|
+
- Rules are sorted alphabetically by title within each section
|
|
158
|
+
|
|
159
|
+
## Impact Levels
|
|
160
|
+
|
|
161
|
+
- `CRITICAL` - Highest priority, causes crashes or broken UI
|
|
162
|
+
- `HIGH` - Significant performance improvements
|
|
163
|
+
- `MEDIUM` - Moderate performance improvements
|
|
164
|
+
- `LOW` - Incremental improvements
|
|
165
|
+
```
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vercel-react-native-skills
|
|
3
|
+
description:
|
|
4
|
+
React Native and Expo best practices for building performant mobile apps. Use
|
|
5
|
+
when building React Native components, optimizing list performance,
|
|
6
|
+
implementing animations, or working with native modules. Triggers on tasks
|
|
7
|
+
involving React Native, Expo, mobile performance, or native platform APIs.
|
|
8
|
+
license: MIT
|
|
9
|
+
metadata:
|
|
10
|
+
author: vercel
|
|
11
|
+
version: '1.0.0'
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# React Native Skills
|
|
15
|
+
|
|
16
|
+
Comprehensive best practices for React Native and Expo applications. Contains
|
|
17
|
+
rules across multiple categories covering performance, animations, UI patterns,
|
|
18
|
+
and platform-specific optimizations.
|
|
19
|
+
|
|
20
|
+
## When to Apply
|
|
21
|
+
|
|
22
|
+
Reference these guidelines when:
|
|
23
|
+
|
|
24
|
+
- Building React Native or Expo apps
|
|
25
|
+
- Optimizing list and scroll performance
|
|
26
|
+
- Implementing animations with Reanimated
|
|
27
|
+
- Working with images and media
|
|
28
|
+
- Configuring native modules or fonts
|
|
29
|
+
- Structuring monorepo projects with native dependencies
|
|
30
|
+
|
|
31
|
+
## Rule Categories by Priority
|
|
32
|
+
|
|
33
|
+
| Priority | Category | Impact | Prefix |
|
|
34
|
+
| -------- | ---------------- | -------- | -------------------- |
|
|
35
|
+
| 1 | List Performance | CRITICAL | `list-performance-` |
|
|
36
|
+
| 2 | Animation | HIGH | `animation-` |
|
|
37
|
+
| 3 | Navigation | HIGH | `navigation-` |
|
|
38
|
+
| 4 | UI Patterns | HIGH | `ui-` |
|
|
39
|
+
| 5 | State Management | MEDIUM | `react-state-` |
|
|
40
|
+
| 6 | Rendering | MEDIUM | `rendering-` |
|
|
41
|
+
| 7 | Monorepo | MEDIUM | `monorepo-` |
|
|
42
|
+
| 8 | Configuration | LOW | `fonts-`, `imports-` |
|
|
43
|
+
|
|
44
|
+
## Quick Reference
|
|
45
|
+
|
|
46
|
+
### 1. List Performance (CRITICAL)
|
|
47
|
+
|
|
48
|
+
- `list-performance-virtualize` - Use FlashList for large lists
|
|
49
|
+
- `list-performance-item-memo` - Memoize list item components
|
|
50
|
+
- `list-performance-callbacks` - Stabilize callback references
|
|
51
|
+
- `list-performance-inline-objects` - Avoid inline style objects
|
|
52
|
+
- `list-performance-function-references` - Extract functions outside render
|
|
53
|
+
- `list-performance-images` - Optimize images in lists
|
|
54
|
+
- `list-performance-item-expensive` - Move expensive work outside items
|
|
55
|
+
- `list-performance-item-types` - Use item types for heterogeneous lists
|
|
56
|
+
|
|
57
|
+
### 2. Animation (HIGH)
|
|
58
|
+
|
|
59
|
+
- `animation-gpu-properties` - Animate only transform and opacity
|
|
60
|
+
- `animation-derived-value` - Use useDerivedValue for computed animations
|
|
61
|
+
- `animation-gesture-detector-press` - Use Gesture.Tap instead of Pressable
|
|
62
|
+
|
|
63
|
+
### 3. Navigation (HIGH)
|
|
64
|
+
|
|
65
|
+
- `navigation-native-navigators` - Use native stack and native tabs over JS navigators
|
|
66
|
+
|
|
67
|
+
### 4. UI Patterns (HIGH)
|
|
68
|
+
|
|
69
|
+
- `ui-expo-image` - Use expo-image for all images
|
|
70
|
+
- `ui-image-gallery` - Use Galeria for image lightboxes
|
|
71
|
+
- `ui-pressable` - Use Pressable over TouchableOpacity
|
|
72
|
+
- `ui-safe-area-scroll` - Handle safe areas in ScrollViews
|
|
73
|
+
- `ui-scrollview-content-inset` - Use contentInset for headers
|
|
74
|
+
- `ui-menus` - Use native context menus
|
|
75
|
+
- `ui-native-modals` - Use native modals when possible
|
|
76
|
+
- `ui-measure-views` - Use onLayout, not measure()
|
|
77
|
+
- `ui-styling` - Use StyleSheet.create or Nativewind
|
|
78
|
+
|
|
79
|
+
### 5. State Management (MEDIUM)
|
|
80
|
+
|
|
81
|
+
- `react-state-minimize` - Minimize state subscriptions
|
|
82
|
+
- `react-state-dispatcher` - Use dispatcher pattern for callbacks
|
|
83
|
+
- `react-state-fallback` - Show fallback on first render
|
|
84
|
+
- `react-compiler-destructure-functions` - Destructure for React Compiler
|
|
85
|
+
- `react-compiler-reanimated-shared-values` - Handle shared values with compiler
|
|
86
|
+
|
|
87
|
+
### 6. Rendering (MEDIUM)
|
|
88
|
+
|
|
89
|
+
- `rendering-text-in-text-component` - Wrap text in Text components
|
|
90
|
+
- `rendering-no-falsy-and` - Avoid falsy && for conditional rendering
|
|
91
|
+
|
|
92
|
+
### 7. Monorepo (MEDIUM)
|
|
93
|
+
|
|
94
|
+
- `monorepo-native-deps-in-app` - Keep native dependencies in app package
|
|
95
|
+
- `monorepo-single-dependency-versions` - Use single versions across packages
|
|
96
|
+
|
|
97
|
+
### 8. Configuration (LOW)
|
|
98
|
+
|
|
99
|
+
- `fonts-config-plugin` - Use config plugins for custom fonts
|
|
100
|
+
- `imports-design-system-folder` - Organize design system imports
|
|
101
|
+
- `js-hoist-intl` - Hoist Intl object creation
|
|
102
|
+
|
|
103
|
+
## How to Use
|
|
104
|
+
|
|
105
|
+
Read individual rule files for detailed explanations and code examples:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
rules/list-performance-virtualize.md
|
|
109
|
+
rules/animation-gpu-properties.md
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Each rule file contains:
|
|
113
|
+
|
|
114
|
+
- Brief explanation of why it matters
|
|
115
|
+
- Incorrect code example with explanation
|
|
116
|
+
- Correct code example with explanation
|
|
117
|
+
- Additional context and references
|
|
118
|
+
|
|
119
|
+
## Full Compiled Document
|
|
120
|
+
|
|
121
|
+
For the complete guide with all rules expanded: `AGENTS.md`
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Prefer useDerivedValue Over useAnimatedReaction
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: cleaner code, automatic dependency tracking
|
|
5
|
+
tags: animation, reanimated, derived-value
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Prefer useDerivedValue Over useAnimatedReaction
|
|
9
|
+
|
|
10
|
+
When deriving a shared value from another, use `useDerivedValue` instead of
|
|
11
|
+
`useAnimatedReaction`. Derived values are declarative, automatically track
|
|
12
|
+
dependencies, and return a value you can use directly. Animated reactions are
|
|
13
|
+
for side effects, not derivations.
|
|
14
|
+
|
|
15
|
+
**Incorrect (useAnimatedReaction for derivation):**
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { useSharedValue, useAnimatedReaction } from 'react-native-reanimated'
|
|
19
|
+
|
|
20
|
+
function MyComponent() {
|
|
21
|
+
const progress = useSharedValue(0)
|
|
22
|
+
const opacity = useSharedValue(1)
|
|
23
|
+
|
|
24
|
+
useAnimatedReaction(
|
|
25
|
+
() => progress.value,
|
|
26
|
+
(current) => {
|
|
27
|
+
opacity.value = 1 - current
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
// ...
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Correct (useDerivedValue):**
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { useSharedValue, useDerivedValue } from 'react-native-reanimated'
|
|
39
|
+
|
|
40
|
+
function MyComponent() {
|
|
41
|
+
const progress = useSharedValue(0)
|
|
42
|
+
|
|
43
|
+
const opacity = useDerivedValue(() => 1 - progress.get())
|
|
44
|
+
|
|
45
|
+
// ...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Use `useAnimatedReaction` only for side effects that don't produce a value
|
|
50
|
+
(e.g., triggering haptics, logging, calling `runOnJS`).
|
|
51
|
+
|
|
52
|
+
Reference:
|
|
53
|
+
[Reanimated useDerivedValue](https://docs.swmansion.com/react-native-reanimated/docs/core/useDerivedValue)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use GestureDetector for Animated Press States
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: UI thread animations, smoother press feedback
|
|
5
|
+
tags: animation, gestures, press, reanimated
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use GestureDetector for Animated Press States
|
|
9
|
+
|
|
10
|
+
For animated press states (scale, opacity on press), use `GestureDetector` with
|
|
11
|
+
`Gesture.Tap()` and shared values instead of Pressable's
|
|
12
|
+
`onPressIn`/`onPressOut`. Gesture callbacks run on the UI thread as worklets—no
|
|
13
|
+
JS thread round-trip for press animations.
|
|
14
|
+
|
|
15
|
+
**Incorrect (Pressable with JS thread callbacks):**
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Pressable } from 'react-native'
|
|
19
|
+
import Animated, {
|
|
20
|
+
useSharedValue,
|
|
21
|
+
useAnimatedStyle,
|
|
22
|
+
withTiming,
|
|
23
|
+
} from 'react-native-reanimated'
|
|
24
|
+
|
|
25
|
+
function AnimatedButton({ onPress }: { onPress: () => void }) {
|
|
26
|
+
const scale = useSharedValue(1)
|
|
27
|
+
|
|
28
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
29
|
+
transform: [{ scale: scale.value }],
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Pressable
|
|
34
|
+
onPress={onPress}
|
|
35
|
+
onPressIn={() => (scale.value = withTiming(0.95))}
|
|
36
|
+
onPressOut={() => (scale.value = withTiming(1))}
|
|
37
|
+
>
|
|
38
|
+
<Animated.View style={animatedStyle}>
|
|
39
|
+
<Text>Press me</Text>
|
|
40
|
+
</Animated.View>
|
|
41
|
+
</Pressable>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Correct (GestureDetector with UI thread worklets):**
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler'
|
|
50
|
+
import Animated, {
|
|
51
|
+
useSharedValue,
|
|
52
|
+
useAnimatedStyle,
|
|
53
|
+
withTiming,
|
|
54
|
+
interpolate,
|
|
55
|
+
runOnJS,
|
|
56
|
+
} from 'react-native-reanimated'
|
|
57
|
+
|
|
58
|
+
function AnimatedButton({ onPress }: { onPress: () => void }) {
|
|
59
|
+
// Store the press STATE (0 = not pressed, 1 = pressed)
|
|
60
|
+
const pressed = useSharedValue(0)
|
|
61
|
+
|
|
62
|
+
const tap = Gesture.Tap()
|
|
63
|
+
.onBegin(() => {
|
|
64
|
+
pressed.set(withTiming(1))
|
|
65
|
+
})
|
|
66
|
+
.onFinalize(() => {
|
|
67
|
+
pressed.set(withTiming(0))
|
|
68
|
+
})
|
|
69
|
+
.onEnd(() => {
|
|
70
|
+
runOnJS(onPress)()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// Derive visual values from the state
|
|
74
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
75
|
+
transform: [
|
|
76
|
+
{ scale: interpolate(withTiming(pressed.get()), [0, 1], [1, 0.95]) },
|
|
77
|
+
],
|
|
78
|
+
}))
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<GestureDetector gesture={tap}>
|
|
82
|
+
<Animated.View style={animatedStyle}>
|
|
83
|
+
<Text>Press me</Text>
|
|
84
|
+
</Animated.View>
|
|
85
|
+
</GestureDetector>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Store the press **state** (0 or 1), then derive the scale via `interpolate`.
|
|
91
|
+
This keeps the shared value as ground truth. Use `runOnJS` to call JS functions
|
|
92
|
+
from worklets. Use `.set()` and `.get()` for React Compiler compatibility.
|
|
93
|
+
|
|
94
|
+
Reference:
|
|
95
|
+
[Gesture Handler Tap Gesture](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Animate Transform and Opacity Instead of Layout Properties
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: GPU-accelerated animations, no layout recalculation
|
|
5
|
+
tags: animation, performance, reanimated, transform, opacity
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Animate Transform and Opacity Instead of Layout Properties
|
|
9
|
+
|
|
10
|
+
Avoid animating `width`, `height`, `top`, `left`, `margin`, or `padding`. These trigger layout recalculation on every frame. Instead, use `transform` (scale, translate) and `opacity` which run on the GPU without triggering layout.
|
|
11
|
+
|
|
12
|
+
**Incorrect (animates height, triggers layout every frame):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
|
|
16
|
+
|
|
17
|
+
function CollapsiblePanel({ expanded }: { expanded: boolean }) {
|
|
18
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
19
|
+
height: withTiming(expanded ? 200 : 0), // triggers layout on every frame
|
|
20
|
+
overflow: 'hidden',
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
return <Animated.View style={animatedStyle}>{children}</Animated.View>
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Correct (animates scaleY, GPU-accelerated):**
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
|
|
31
|
+
|
|
32
|
+
function CollapsiblePanel({ expanded }: { expanded: boolean }) {
|
|
33
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
34
|
+
transform: [
|
|
35
|
+
{ scaleY: withTiming(expanded ? 1 : 0) },
|
|
36
|
+
],
|
|
37
|
+
opacity: withTiming(expanded ? 1 : 0),
|
|
38
|
+
}))
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Animated.View style={[{ height: 200, transformOrigin: 'top' }, animatedStyle]}>
|
|
42
|
+
{children}
|
|
43
|
+
</Animated.View>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Correct (animates translateY for slide animations):**
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
|
|
52
|
+
|
|
53
|
+
function SlideIn({ visible }: { visible: boolean }) {
|
|
54
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
55
|
+
transform: [
|
|
56
|
+
{ translateY: withTiming(visible ? 0 : 100) },
|
|
57
|
+
],
|
|
58
|
+
opacity: withTiming(visible ? 1 : 0),
|
|
59
|
+
}))
|
|
60
|
+
|
|
61
|
+
return <Animated.View style={animatedStyle}>{children}</Animated.View>
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
GPU-accelerated properties: `transform` (translate, scale, rotate), `opacity`. Everything else triggers layout.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Compound Components Over Polymorphic Children
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: flexible composition, clearer API
|
|
5
|
+
tags: design-system, components, composition
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Compound Components Over Polymorphic Children
|
|
9
|
+
|
|
10
|
+
Don't create components that can accept a string if they aren't a text node. If
|
|
11
|
+
a component can receive a string child, it must be a dedicated `*Text`
|
|
12
|
+
component. For components like buttons, which can have both a View (or
|
|
13
|
+
Pressable) together with text, use compound components, such a `Button`,
|
|
14
|
+
`ButtonText`, and `ButtonIcon`.
|
|
15
|
+
|
|
16
|
+
**Incorrect (polymorphic children):**
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { Pressable, Text } from 'react-native'
|
|
20
|
+
|
|
21
|
+
type ButtonProps = {
|
|
22
|
+
children: string | React.ReactNode
|
|
23
|
+
icon?: React.ReactNode
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function Button({ children, icon }: ButtonProps) {
|
|
27
|
+
return (
|
|
28
|
+
<Pressable>
|
|
29
|
+
{icon}
|
|
30
|
+
{typeof children === 'string' ? <Text>{children}</Text> : children}
|
|
31
|
+
</Pressable>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Usage is ambiguous
|
|
36
|
+
<Button icon={<Icon />}>Save</Button>
|
|
37
|
+
<Button><CustomText>Save</CustomText></Button>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Correct (compound components):**
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { Pressable, Text } from 'react-native'
|
|
44
|
+
|
|
45
|
+
function Button({ children }: { children: React.ReactNode }) {
|
|
46
|
+
return <Pressable>{children}</Pressable>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function ButtonText({ children }: { children: React.ReactNode }) {
|
|
50
|
+
return <Text>{children}</Text>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ButtonIcon({ children }: { children: React.ReactNode }) {
|
|
54
|
+
return <>{children}</>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Usage is explicit and composable
|
|
58
|
+
<Button>
|
|
59
|
+
<ButtonIcon><SaveIcon /></ButtonIcon>
|
|
60
|
+
<ButtonText>Save</ButtonText>
|
|
61
|
+
</Button>
|
|
62
|
+
|
|
63
|
+
<Button>
|
|
64
|
+
<ButtonText>Cancel</ButtonText>
|
|
65
|
+
</Button>
|
|
66
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Load fonts natively at build time
|
|
3
|
+
impact: LOW
|
|
4
|
+
impactDescription: fonts available at launch, no async loading
|
|
5
|
+
tags: fonts, expo, performance, config-plugin
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Expo Config Plugin for Font Loading
|
|
9
|
+
|
|
10
|
+
Use the `expo-font` config plugin to embed fonts at build time instead of
|
|
11
|
+
`useFonts` or `Font.loadAsync`. Embedded fonts are more efficient.
|
|
12
|
+
|
|
13
|
+
**Incorrect (async font loading):**
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useFonts } from 'expo-font'
|
|
17
|
+
import { Text, View } from 'react-native'
|
|
18
|
+
|
|
19
|
+
function App() {
|
|
20
|
+
const [fontsLoaded] = useFonts({
|
|
21
|
+
'Geist-Bold': require('./assets/fonts/Geist-Bold.otf'),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (!fontsLoaded) {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<View>
|
|
30
|
+
<Text style={{ fontFamily: 'Geist-Bold' }}>Hello</Text>
|
|
31
|
+
</View>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Correct (config plugin, fonts embedded at build):**
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
// app.json
|
|
40
|
+
{
|
|
41
|
+
"expo": {
|
|
42
|
+
"plugins": [
|
|
43
|
+
[
|
|
44
|
+
"expo-font",
|
|
45
|
+
{
|
|
46
|
+
"fonts": ["./assets/fonts/Geist-Bold.otf"]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { Text, View } from 'react-native'
|
|
56
|
+
|
|
57
|
+
function App() {
|
|
58
|
+
// No loading state needed—font is already available
|
|
59
|
+
return (
|
|
60
|
+
<View>
|
|
61
|
+
<Text style={{ fontFamily: 'Geist-Bold' }}>Hello</Text>
|
|
62
|
+
</View>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
After adding fonts to the config plugin, run `npx expo prebuild` and rebuild the
|
|
68
|
+
native app.
|
|
69
|
+
|
|
70
|
+
Reference:
|
|
71
|
+
[Expo Font Documentation](https://docs.expo.dev/versions/latest/sdk/font/)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Import from Design System Folder
|
|
3
|
+
impact: LOW
|
|
4
|
+
impactDescription: enables global changes and easy refactoring
|
|
5
|
+
tags: imports, architecture, design-system
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Import from Design System Folder
|
|
9
|
+
|
|
10
|
+
Re-export dependencies from a design system folder. App code imports from there,
|
|
11
|
+
not directly from packages. This enables global changes and easy refactoring.
|
|
12
|
+
|
|
13
|
+
**Incorrect (imports directly from package):**
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { View, Text } from 'react-native'
|
|
17
|
+
import { Button } from '@ui/button'
|
|
18
|
+
|
|
19
|
+
function Profile() {
|
|
20
|
+
return (
|
|
21
|
+
<View>
|
|
22
|
+
<Text>Hello</Text>
|
|
23
|
+
<Button>Save</Button>
|
|
24
|
+
</View>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Correct (imports from design system):**
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// components/view.tsx
|
|
33
|
+
import { View as RNView } from 'react-native'
|
|
34
|
+
|
|
35
|
+
// ideal: pick the props you will actually use to control implementation
|
|
36
|
+
export function View(
|
|
37
|
+
props: Pick<React.ComponentProps<typeof RNView>, 'style' | 'children'>
|
|
38
|
+
) {
|
|
39
|
+
return <RNView {...props} />
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// components/text.tsx
|
|
45
|
+
export { Text } from 'react-native'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// components/button.tsx
|
|
50
|
+
export { Button } from '@ui/button'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { View } from '@/components/view'
|
|
55
|
+
import { Text } from '@/components/text'
|
|
56
|
+
import { Button } from '@/components/button'
|
|
57
|
+
|
|
58
|
+
function Profile() {
|
|
59
|
+
return (
|
|
60
|
+
<View>
|
|
61
|
+
<Text>Hello</Text>
|
|
62
|
+
<Button>Save</Button>
|
|
63
|
+
</View>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Start by simply re-exporting. Customize later without changing app code.
|