Rails Flash messages for user feedback

Flash messages provide one-time notifications across requests, perfect for confirming actions or showing errors. I use flash[:notice] for success messages and flash[:alert] for errors. Flash persists in session storage for one request, then auto-delet

Intersection Observer API for visibility tracking

The Intersection Observer API efficiently detects when elements enter/exit the viewport, enabling lazy loading, infinite scroll, and analytics without expensive scroll listeners. I create observers with thresholds defining when callbacks trigger—0.0 m

Rails service objects for business logic

Service objects encapsulate complex business logic that doesn't belong in models or controllers. Each service performs one operation, like creating a post with side effects, processing a payment, or importing data. I create services in app/services wi

React useReducer for complex state logic

useReducer manages state with reducer patterns like Redux but locally scoped. When state updates depend on previous state or involve multiple sub-values, reducers are clearer than multiple useState calls. The reducer function takes current state and a

Rails API versioning strategies

API versioning allows backward-incompatible changes without breaking existing clients. I version via URL path (/api/v1/posts) for simplicity and explicit version selection. Each version namespace has its own controllers and serializers. Routes use nam

React Hook Form with async validation

Async validation checks constraints that require server communication, like username availability or email uniqueness. React Hook Form's validate option accepts async functions that return error messages or true. I debounce async validators to avoid e

Rails validators for custom business logic

Custom validators encapsulate complex validation rules that go beyond built-in validators. I create validator classes for business logic like email format verification, slug uniqueness, or credit card validation. Custom validators inherit from ActiveM

CORS configuration for Rails APIs

Cross-Origin Resource Sharing (CORS) allows browsers to make requests from React apps hosted on different domains than the Rails API. The rack-cors gem configures CORS middleware with fine-grained control over origins, methods, and headers. In develop

React memo for component optimization

React.memo prevents unnecessary re-renders of components when props haven't changed. I wrap components in memo when they're expensive to render or receive the same props frequently. The component only re-renders if props differ via shallow comparison.

Rails N+1 query detection with Bullet

N+1 queries are the most common Rails performance problem—loading associations in loops causes exponential database queries. The Bullet gem detects N+1s in development and suggests fixes. It monitors queries and alerts when you should use includes, pr

Keyboard navigation and focus management

Accessible apps support keyboard-only navigation with proper focus management. Tab order should follow visual order, and all interactive elements must be keyboard accessible. I use tabIndex={0} to make custom controls focusable and tabIndex={-1} for p

Rails fixtures vs factories for test data

Fixtures and factories both create test data, but suit different needs. Fixtures load YAML files into the database before tests, providing fast, consistent data. I use fixtures for static reference data like countries or categories. Factories (via Fac