styled-thing, a lightweight alternative to styled-components optimized for React Native.
Overview
styled-thing provides a familiar styled-components-like API with better performance characteristics for React Native:
- Object syntax only - No template literals, uses object styles
- React.memo optimization - Components are memoized with fast equality checks
- Prop filtering - Supports
shouldForwardPropfor prop filtering - Polymorphic rendering - Use
asor$asprop to change rendered component - Theme support - Access theme via context
Basic Usage
Creating Styled Components
Dynamic Styles with Props
Styles can be functions that receive props:Advanced Features
Prop Filtering with shouldForwardProp
Prevent certain props from being passed to the underlying component:Attrs for Default Props
Useattrs to set default props or derive props:
Composing Styled Components
Style existing styled components:Polymorphic Components with as
Render as a different component:Theme Support
Theme Provider
Accessing Theme in Styled Components
CSS Prop
styled-thing supports inline styles via the css prop:
Important Differences from styled-components
1. Object Syntax Only
2. Dollar Sign Props Convention
Use$ prefix for custom props to prevent forwarding:
3. Style Arrays
Multiple styles are flattened into an array:Performance Optimization
React.memo Integration
All styled components are automatically wrapped withReact.memo using fast comparison:
Avoiding Re-renders
Extract static styles and use prop functions only when needed:Common Patterns
Conditional Styles
Responsive Styles
Platform-Specific Styles
Best Practices
1. Colocate Styled Components
Define styled components near their usage:2. Use TypeScript
Always type your styled component props:3. Prefer Design System Components
Use design system components over styled-thing when possible:4. Extract Complex Style Logic
Migrating from styled-components
If you’re familiar with styled-components, here are the key changes:| Feature | styled-components | styled-thing |
|---|---|---|
| Syntax | Template literals | Object syntax only |
| Prop prefix | $ optional | $ recommended |
| Theme access | ${p => p.theme} | ({ theme }) => theme |
| Memoization | Manual | Automatic with fast-compare |
| shouldForwardProp | .withConfig() | .withConfig() |
| attrs | .attrs() | .attrs() |
Aliases
styled-thing provides aliases for all React Native components: