← Back to list

react-typescript
by octave-commons
A myth engine
⭐ 1🍴 0📅 Jan 25, 2026
SKILL.md
name: react-typescript description: React 19 + TypeScript patterns, hooks, types, and best practices license: MIT compatibility: opencode metadata: audience: frontend-developers frameworks: react typescript
What I do
- Create type-safe React components with TypeScript
- Use React hooks correctly (useState, useEffect, useMemo, useRef)
- Type props, state, and event handlers
- Optimize re-renders with memoization and keys
- Implement context providers and custom hooks
- Handle forms, async operations, and error boundaries
When to use me
Use me when building React + TypeScript applications, especially when:
- Creating new components or refactoring existing ones
- Adding types to props and state
- Implementing complex hooks or context patterns
- Optimizing performance (memo, useMemo, useCallback)
- Handling forms and user input
- Debugging TypeScript errors
Component patterns
interface Props {
title: string;
count: number;
onIncrement?: () => void;
}
export function Counter({ title, count, onIncrement }: Props) {
return (
<div>
<h1>{title}</h1>
<p>Count: {count}</p>
<button onClick={onIncrement}>Increment</button>
</div>
);
}
Hook usage patterns
useState<T>(initialValue)- Type state explicitly if inferreduseEffect(() => { ... }, [deps])- Include all dependenciesuseMemo(() => expensive(a, b), [a, b])- Memoize expensive valuesuseCallback(() => action(a, b), [a, b])- Memoize callbacksuseRef<T>(null)- Type refs with genericuseContext(Context)- Type context with Context type
Type definitions
// Props with optional and union types
interface ButtonProps {
variant: 'primary' | 'secondary';
disabled?: boolean;
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
}
// Generic components
interface ListProps<T> {
items: T[];
render: (item: T) => React.ReactNode;
}
function List<T>({ items, render }: ListProps<T>) {
return <ul>{items.map(render)}</ul>;
}
Event handling
// Form events
handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
// Access form: event.currentTarget.elements.name.value
}
// Input events
handleChange(event: React.ChangeEvent<HTMLInputElement>) {
setValue(event.target.value);
}
// Mouse events
handleClick(event: React.MouseEvent<HTMLButtonElement>) {
console.log(event.clientX, event.clientY);
}
Performance optimization
- Use
React.memofor components that shouldn't re-render - Memoize with
useMemofor expensive calculations - Memoize callbacks with
useCallbackfor child props - Provide stable keys for lists (use IDs, not indexes)
- Avoid creating new objects/arrays in render
Context patterns
// Create typed context
interface AppContext {
user: User | null;
login: (email: string) => Promise<void>;
}
const AppContext = createContext<AppContext | null>(null);
// Provider component
function AppProvider({ children }: { children: React.ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const login = useCallback(async (email: string) => {
// ...
}, []);
return (
<AppContext.Provider value={{ user, login }}>
{children}
</AppContext.Provider>
);
}
// Custom hook to use context
function useApp() {
const context = useContext(AppContext);
if (!context) throw new Error('useApp must be used within AppProvider');
return context;
}
Error boundaries
interface ErrorBoundaryProps {
children: React.ReactNode;
fallback?: React.ReactNode;
}
class ErrorBoundary extends Component<ErrorBoundaryProps, { error: Error | null }> {
state = { error: null };
static getDerivedStateFromError(error: Error) {
return { error };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error('Error caught:', error, errorInfo);
}
render() {
if (this.state.error) {
return this.props.fallback || <div>Something went wrong</div>;
}
return this.props.children;
}
}
Form handling
- Use controlled components with state
- Type form data with interfaces
- Validate before submission
- Handle loading and error states
- Use
useFormfrom libraries (react-hook-form) for complex forms
Strict mode
- Always use
<React.StrictMode>in development - Detects side effects and unsafe lifecycles
- Invokes effects twice in dev to catch bugs
- Enables React DevTools profiling
TypeScript strict mode
- Enable
"strict": truein tsconfig.json - Use
unknowninstead ofanyfor dynamic data - Type API responses with interfaces
- Use discriminated unions for state machines
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon