| name | frontend-best-practices |
| description | Senior Front-End Developer guidance for ReactJS, NextJS, JavaScript, TypeScript, HTML, CSS and modern UI/UX frameworks. Use when building front-end applications, writing React/Next.js code, or implementing UI components. Triggers on: frontend, react, nextjs, typescript, tailwindcss, ui development. |
Front-End Best Practices
Senior Front-End Developer guidance for modern web development.
Coding Environment
The user asks questions about the following coding languages:
- ReactJS
- NextJS
- JavaScript
- TypeScript
- TailwindCSS
- HTML
- CSS
Code Implementation Guidelines
Early Returns
function getUserName(user: User | null): string {
if (!user) return 'Anonymous';
if (!user.name) return 'Unknown';
return user.name;
}
function getUserName(user: User | null): string {
if (user) {
if (user.name) {
return user.name;
} else {
return 'Unknown';
}
} else {
return 'Anonymous';
}
}
TailwindCSS Styling
<button className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Click me
</button>
<button style={{ padding: '8px 16px', backgroundColor: 'blue' }}>
Click me
</button>
Descriptive Naming
const isLoading = false;
const hasError = true;
const canEdit = true;
const handleClick = () => {};
const handleKeyDown = () => {};
const handleSubmit = () => {};
const flag = false;
const err = true;
const edit = true;
const click = () => {};
const keyDown = () => {};
Accessibility Features
<div
role="button"
tabIndex={0}
aria-label="Toggle menu"
onClick={handleClick}
onKeyDown={handleKeyDown}
>
Menu
</div>
<div onClick={handleClick}>
Menu
</div>
Const Over Function
const toggle = () => setIsOpen(!isOpen);
const fetchData = async () => { };
function toggle() {
setIsOpen(!isOpen);
}
No Semicolons (Optional)
const name = 'John'
const greeting = `Hello ${name}`
const name = 'John';
const greeting = `Hello ${name}`;
Commit Guidelines
Commit Format
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types
| Type | Description | Version |
|---|
feat | New feature | MINOR |
fix | Bug fix | PATCH |
chore | Maintenance | - |
docs | Documentation | - |
style | Formatting | - |
refactor | Code refactoring | - |
perf | Performance | - |
test | Tests | - |
Examples
feat(auth): add OAuth2 login support
fix(api): resolve race condition in data fetching
docs(readme): update installation instructions
refactor(utils): simplify date formatting logic
Best Practices
- Follow the user's requirements carefully & to the letter
- Think step-by-step - describe your plan in pseudocode first
- Confirm, then write code
- Always write correct, best practice, DRY principle, bug free, fully functional code
- Focus on easy and readability code, over being performant
- Fully implement all requested functionality
- Leave NO todo's, placeholders or missing pieces
- Ensure code is complete! Verify thoroughly
- Include all required imports, and ensure proper naming of key components
- Be concise - minimize any other prose
Activation Keywords
frontend-best-practices
frontend-best-practices
frontend best practices
Tools Used
Instructions for Agents
- Read the task description carefully
- Follow the step-by-step process
- Use the appropriate tools
- Verify the results
Examples
Example 1: Basic Usage
User:
Agent:
Example 2: Advanced Usage
User:
Agent: