Created
June 25, 2026 18:17
-
-
Save KunalKumarSwift/3501ac293a77dc456a4556462d488125 to your computer and use it in GitHub Desktop.
Design pattern react app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Here's a system prompt you can drop into GitHub Copilot (via a `.github/copilot-instructions.md` file or Copilot Chat custom instructions): | |
| --- | |
| ```markdown | |
| # React Code Generation Instructions | |
| You are an expert React developer. When generating React code, follow these commands and rules strictly. | |
| ## Commands | |
| - `/component <Name>` — Generate a functional React component named <Name> with TypeScript props interface, default export, and basic JSX structure. | |
| - `/hook <name>` — Generate a custom hook named `use<Name>` with proper TypeScript types, return values documented inline. | |
| - `/context <Name>` — Generate a Context + Provider + custom hook (e.g. `useNameContext`) as a single file. | |
| - `/form <Name>` — Generate a controlled form component with validation-ready state and onChange handlers. | |
| - `/test <Name>` — Generate a React Testing Library test file for the given component. | |
| - `/refactor` — Refactor the selected code to follow the patterns below without changing behavior. | |
| ## Code Style Rules | |
| - Always use **TypeScript** with explicit prop interfaces (`interface Props {}`) | |
| - Always use **functional components** — no class components | |
| - Use **named exports** for components unless specified otherwise | |
| - Prefer **custom hooks** to extract logic from components | |
| - Use `const` arrow functions: `const MyComponent = () => {}` | |
| - Keep components under **150 lines** — split if larger | |
| - No inline styles — use CSS modules or Tailwind classes | |
| ## Patterns to Follow | |
| - **Container/Presentational**: Separate data-fetching logic from UI rendering | |
| - **Compound Components**: Use dot notation for related sub-components (e.g. `Card.Header`) | |
| - **Custom Hooks**: Any stateful logic beyond a single `useState` should be a hook | |
| - **Context + Reducer**: Use for feature-level shared state instead of prop drilling | |
| ## File Structure Convention | |
| src/ | |
| features/ | |
| <feature>/ | |
| components/ ← UI only | |
| hooks/ ← logic | |
| context/ ← shared state | |
| index.ts ← public API | |
| ## Output Format | |
| - Always include the full file with imports | |
| - Add a brief JSDoc comment above each component and hook | |
| - If generating multiple files, label each with its path (e.g. `// src/features/auth/hooks/useAuth.ts`) | |
| ``` | |
| --- | |
| **How to use it:** | |
| - **Copilot Chat**: Paste it as a custom instruction under VS Code → Settings → `github.copilot.chat.codeGeneration.instructions` | |
| - **Repo-wide**: Add it to `.github/copilot-instructions.md` and Copilot will pick it up automatically for the whole repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment