react-native-web-core
$
npx mdskill add TheBushidoCollective/han/react-native-web-coreBuild unified web and native apps using shared React Native code.
- Developers create single codebases that run on both web and mobile.
- The skill uses React Native primitives like View and Text instead of HTML.
- It leverages the Platform module to handle platform-specific logic.
- Results are delivered through consistent API patterns across all devices.
SKILL.md
.github/skills/react-native-web-coreView on GitHub ↗
---
name: react-native-web-core
user-invocable: false
description: Use when working with React Native Web projects. Provides core concepts, components, and cross-platform patterns for building web applications with React Native.
allowed-tools:
- Read
- Write
- Edit
- Bash
- Grep
- Glob
---
# React Native Web - Core Concepts
React Native Web enables React Native components and APIs to run on the web, providing a unified codebase for web and native platforms.
## Key Concepts
### Platform Abstraction
React Native Web provides a consistent API across web and native platforms:
```typescript
import { View, Text, StyleSheet } from 'react-native';
export function MyComponent() {
return (
<View style={styles.container}>
<Text style={styles.text}>Works on web and native!</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 16,
color: '#333',
},
});
```
### Core Components
Use React Native primitives instead of HTML elements:
- `<View>` instead of `<div>`
- `<Text>` instead of `<span>` or `<p>`
- `<Image>` instead of `<img>`
- `<TextInput>` instead of `<input>`
- `<ScrollView>` instead of scrollable `<div>`
- `<Pressable>` instead of `<button>`
### Platform-Specific Code
Use `Platform` module for platform-specific behavior:
```typescript
import { Platform } from 'react-native';
const styles = StyleSheet.create({
container: {
marginTop: Platform.select({
web: 20,
ios: 30,
android: 25,
default: 20,
}),
},
});
// Or use Platform.OS
if (Platform.OS === 'web') {
// Web-specific code
}
```
## Best Practices
### Component Structure
✅ Use React Native primitives consistently:
```typescript
import { View, Text, Pressable } from 'react-native';
function Button({ onPress, title }: { onPress: () => void; title: string }) {
return (
<Pressable onPress={onPress}>
<View style={styles.button}>
<Text style={styles.buttonText}>{title}</Text>
</View>
</Pressable>
);
}
```
### Type Safety
✅ Use TypeScript for prop types:
```typescript
import { ViewStyle, TextStyle, ImageStyle } from 'react-native';
interface Props {
title: string;
onPress: () => void;
style?: ViewStyle;
textStyle?: TextStyle;
disabled?: boolean;
}
export function CustomButton({ title, onPress, style, textStyle, disabled }: Props) {
// Implementation
}
```
### Accessibility
✅ Include accessibility props:
```typescript
<Pressable
accessibilityRole="button"
accessibilityLabel="Submit form"
accessibilityState={{ disabled: isDisabled }}
onPress={handleSubmit}
>
<Text>Submit</Text>
</Pressable>
```
## Examples
### Basic Component
```typescript
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
interface CardProps {
title: string;
description: string;
}
export function Card({ title, description }: CardProps) {
return (
<View style={styles.card}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.description}>{description}</Text>
</View>
);
}
const styles = StyleSheet.create({
card: {
padding: 16,
backgroundColor: '#fff',
borderRadius: 8,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 4,
},
title: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 8,
},
description: {
fontSize: 14,
color: '#666',
},
});
```
### Interactive Component with State
```typescript
import React, { useState } from 'react';
import { View, Text, Pressable, StyleSheet } from 'react-native';
export function Counter() {
const [count, setCount] = useState(0);
return (
<View style={styles.container}>
<Text style={styles.count}>{count}</Text>
<View style={styles.buttons}>
<Pressable style={styles.button} onPress={() => setCount(c => c - 1)}>
<Text style={styles.buttonText}>-</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => setCount(c => c + 1)}>
<Text style={styles.buttonText}>+</Text>
</Pressable>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
padding: 20,
},
count: {
fontSize: 48,
fontWeight: 'bold',
marginBottom: 20,
},
buttons: {
flexDirection: 'row',
gap: 10,
},
button: {
backgroundColor: '#007AFF',
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 8,
},
buttonText: {
color: '#fff',
fontSize: 24,
fontWeight: 'bold',
},
});
```
## Common Patterns
### Layout with Flexbox
```typescript
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
header: {
height: 60,
backgroundColor: '#f8f8f8',
},
content: {
flex: 1,
padding: 16,
},
footer: {
height: 50,
backgroundColor: '#f8f8f8',
},
});
```
### Conditional Rendering
```typescript
function UserProfile({ user }: { user?: User }) {
if (!user) {
return (
<View style={styles.center}>
<Text>Please log in</Text>
</View>
);
}
return (
<View style={styles.profile}>
<Text style={styles.name}>{user.name}</Text>
<Text style={styles.email}>{user.email}</Text>
</View>
);
}
```
## Anti-Patterns
❌ Don't use HTML elements directly:
```typescript
// Bad
function Component() {
return <div><span>Text</span></div>;
}
// Good
function Component() {
return <View><Text>Text</Text></View>;
}
```
❌ Don't use CSS classes:
```typescript
// Bad
<div className="container">Content</div>
// Good
<View style={styles.container}>Content</View>
```
❌ Don't access DOM directly:
```typescript
// Bad
document.getElementById('my-element')
// Good - use refs
const ref = useRef<View>(null);
```
## Related Skills
- **react-native-web-styling**: Advanced styling patterns and responsive design
- **react-native-web-navigation**: Navigation setup and routing
- **react-native-web-performance**: Performance optimization techniques
- **react-native-web-testing**: Testing strategies for React Native Web
More from TheBushidoCollective/han
- absinthe-resolversUse when implementing GraphQL resolvers with Absinthe. Covers resolver patterns, dataloader integration, batching, and error handling.
- absinthe-schemaUse when designing GraphQL schemas with Absinthe. Covers type definitions, interfaces, unions, enums, and schema organization patterns.
- absinthe-subscriptionsUse when implementing real-time GraphQL subscriptions with Absinthe. Covers Phoenix channels, PubSub, and subscription patterns.
- act-docker-setupUse when configuring Docker environments for act, selecting runner images, managing container resources, or troubleshooting Docker-related issues with local GitHub Actions testing.
- act-local-testingUse when testing GitHub Actions workflows locally with act. Covers act CLI usage, Docker configuration, debugging workflows, and troubleshooting common issues when running workflows on your local machine.
- act-workflow-syntaxUse when creating or modifying GitHub Actions workflow files. Provides guidance on workflow syntax, triggers, jobs, steps, and expressions for creating valid GitHub Actions workflows that can be tested locally with act.
- ameba-configurationUse when configuring Ameba rules and settings for Crystal projects including .ameba.yml setup, rule management, severity levels, and code quality enforcement.
- ameba-custom-rulesUse when creating custom Ameba rules for Crystal code analysis including rule development, AST traversal, issue reporting, and rule testing.
- ameba-integrationUse when integrating Ameba into development workflows including CI/CD pipelines, pre-commit hooks, GitHub Actions, and automated code review processes.
- analyze-performanceAnalyze performance metrics and identify slow transactions in Sentry