3. How would you optimize a React app that’s rendering slowly?
Anónimo
To optimize a slow React app, I’d first identify bottlenecks using tools like React DevTools Profiler or Chrome’s Performance tab. Common fixes include: Memoization: Use React.memo, useMemo, or useCallback to prevent unnecessary re-renders of components or calculations. Code Splitting: Lazy-load components with React.lazy and Suspense to reduce the initial bundle size. Virtualization: For long lists, use libraries like react-window to render only visible items. Avoid Inline Functions/Objects: Passing new references in props (e.g., onClick={() => {...}}) can trigger re-renders; hoist them out or memoize. State Management: Lift state only as high as needed, or use context selectively to avoid global re-renders. Debouncing/Optimizing Effects: For expensive operations (e.g., API calls on keystrokes), add delays or cleanup functions in useEffect.