DeepSeek React Component Builder Prompt

You are a senior React developer who writes clean, performant, and accessible components.

Category
💻 Coding
Difficulty
Intermediate
Models
3
Last Updated
2026-06-28
💻 Coding Intermediate react typescript frontend component
Works with
📋 Prompt
You are a senior React developer who writes clean, performant, and accessible components.

Component: [component name]
Purpose: [what it does]
Props: [props needed]
Styling: [styling approach — Tailwind/CSS Modules/styled-components/plain CSS]

Task: Build a complete React component including:

1. TYPESCRIPT INTERFACE: Full prop type definitions with JSDoc comments

2. THE COMPONENT:
- Functional component with correct hooks
- Error state, loading state, and empty state handled
- Accessibility: ARIA labels, keyboard navigation, focus management

3. CUSTOM HOOKS (if applicable): Extract business logic from UI

4. USAGE EXAMPLES: 3 different use cases showing the component

5. TESTING GUIDE: 5 test cases (Jest + React Testing Library)

Format: TypeScript throughout. Code blocks with syntax highlighting.
// SearchableDropdown.tsx
import { useState, useRef, useEffect, useCallback } from 'react';

/** Option item in the dropdown list */
interface Option {
value: string;
label: string;
disabled?: boolean;
}

/** Props for the SearchableDropdown component */
interface SearchableDropdownProps {
/** Array of options to display */
options: Option[];
/** Currently selected value */
value: string | null;
/** Callback fired when selection changes */
onChange: (value: string) => void;
/** Placeholder text for the search input */
placeholder?: string;
/** Disable the entire dropdown */
disabled?: boolean;
/** Custom class name for the container */
className?: string;
}

export function SearchableDropdown({
options,
value,
onChange,
placeholder = 'Search...',
disabled = false,
className = '',
}: SearchableDropdownProps) {
const [isOpen, setIsOpen] = useState(false);
const [search, setSearch] = useState('');
const inputRef = useRef<HTMLInputElement>(null);

const filtered = options.filter(o =>
o.label.toLowerCase().includes(search.toLowerCase())
);

// Close on outside click
useEffect(() => {
const handler = (e: MouseEvent) => {
if (!inputRef.current?.closest('.dropdown-root')?.contains(e.target as Node)) {
setIsOpen(false);
}
};
document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
}, []);
...
🏆
Best model for this prompt
DeepSeek
DeepSeek V3 / R1
💡 Pro Tips
Split large components into smaller ones early — a component over 200 lines is usually doing too much
Co-locate related code: types, component, hooks, and tests for one component should be in the same folder
Use React DevTools Profiler before optimising performance — measure first, optimise second
Accessibility is not optional: every interactive element needs a keyboard handler and appropriate ARIA attributes
⚠️ Common Mistakes
Putting everything in one mega-component — makes testing, reuse, and debugging dramatically harder
Over-using useEffect for things that can be calculated during render — derived state doesn't need an effect
Missing the dependency array in useEffect — causes either infinite loops or stale closures
Using array index as the key prop in lists that can change order — causes subtle rendering bugs
❓ FAQ 🔗 Related Prompts