How do you optimize a slow React component?
Profile first, then target expensive calculations, unnecessary renders, large lists, or poorly placed state.
The question library
Explore practical questions, clear explanations, and code examples across developer technologies.
Showing 3133–3144 of 3610 questions
Profile first, then target expensive calculations, unnecessary renders, large lists, or poorly placed state.
Virtualization renders only visible rows and a small buffer, reducing DOM nodes for large lists.
Context shares values needed by many descendants, such as theme, locale, or current user, without passing props through every layer.
Use one when shared client state has complex updates, debugging needs, or coordination across many components.
useReducer manages state through a reducer that receives current state and an action and returns next state.
Define the state type and a discriminated union for actions, then type reducer arguments and return value.
Use a generic such as useRef<HTMLInputElement | null>(null) for a DOM ref initialized to null.
Declare its function signature, such as onSelect: (id: string) => void.
Use React.CSSProperties for inline styles and string for className, or extend native HTML attribute types when wrapping elements.
Validate values, show accessible field errors, manage submission states, and validate again on the server.
onChange responds to input changes; onSubmit handles form submission, including Enter-key submission.
Client-side routing updates the displayed view based on the URL without a full document reload for every navigation.