react-best-practices

Solid

React component patterns, hooks, state management, and performance best practices. Use when building or reviewing React components.

Web & Frontend 30 stars 9 forks Updated 5 days ago MIT

Install

View on GitHub

Quality Score: 82/100

Stars 20%
50
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# React Best Practices ## Component Patterns ### Functional Components Only ```typescript // ✅ Correct interface UserCardProps { user: User onSelect: (id: string) => void } export const UserCard = ({ user, onSelect }: UserCardProps) => { return ( <button onClick={() => onSelect(user.id)} className="..."> {user.name} </button> ) } // ❌ Never use class components class UserCard extends React.Component {} ``` ### Composition Over Props Drilling ```typescript // ✅ Use composition export const Layout = ({ children }: { children: React.ReactNode }) => ( <div className="layout">{children}</div> ) // ✅ Use context for deep data const ThemeContext = createContext<Theme | null>(null) export const useTheme = () => { const theme = useContext(ThemeContext) if (!theme) throw new Error('useTheme must be used within ThemeProvider') return theme } ``` ## Hooks ### Custom Hooks ```typescript // ✅ Extract reusable logic into hooks const useLocalStorage = <T>(key: string, initial: T) => { const [value, setValue] = useState<T>(() => { try { const item = localStorage.getItem(key) return item ? JSON.parse(item) : initial } catch { return initial } }) const set = (val: T) => { setValue(val) localStorage.setItem(key, JSON.stringify(val)) } return [value, set] as const } ``` ### useEffect Rules ```typescript // ✅ Correct — explicit dependencies useEffect(() => { fetchUser(userId) }, [userId]) // ✅ Cleanup w...

Details

Author
sabahattink
Repository
sabahattink/antigravity-fullstack-hq
Created
8 months ago
Last Updated
5 days ago
Language
PowerShell
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category