Skip to content

Commit bcbe499

Browse files
kfaracikclaude
andcommitted
docs: add CLAUDE.md with themed-styles convention
Document the useThemedStyles hook as the required way to build theme-derived StyleSheets, so future work (human or AI) follows it instead of reintroducing the useTheme + useMemo boilerplate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0ee0894 commit bcbe499

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Project conventions
2+
3+
## Themed styles — use the `useThemedStyles` hook
4+
5+
Components that build a `StyleSheet` from the theme MUST obtain it via
6+
[`useThemedStyles`](hooks/useThemedStyles.ts). Do NOT hand-roll the
7+
`useTheme()` + `useMemo(() => createStyles(theme), [theme])` boilerplate.
8+
9+
```tsx
10+
// ✅ styles only
11+
const { styles } = useThemedStyles(createStyles);
12+
13+
// ✅ when the component also reads theme directly (icon colors, insets, etc.)
14+
const { styles, theme } = useThemedStyles(createStyles);
15+
16+
// ✅ parametric factory — pass extra args after the factory
17+
const { styles } = useThemedStyles(createStyles, disabled);
18+
19+
// ❌ do not do this
20+
const { theme } = useTheme();
21+
const styles = useMemo(() => createStyles(theme), [theme]);
22+
```
23+
24+
- Keep the `createStyles = (theme: Theme, ...args) => StyleSheet.create({ ... })`
25+
factory at the bottom of the file, unchanged — the hook memoizes it.
26+
- The hook returns `{ styles, theme }`; destructure only what you use.
27+
- `useTheme()` from [context/ThemeContext](context/ThemeContext.tsx) is still fine
28+
for components that need `theme` but build no `StyleSheet`.

0 commit comments

Comments
 (0)