React Interview Questions: Performance Optimization & State Management

🚀 Real Interview Questions Asked – React (Scenario-Based + Code Snippets) Cracking React interviews today is less about basics and more about real-world problem solving. Here are some actual scenario-driven questions 👇 🔹 1. Prevent Unnecessary Re-renders in Large Lists 👉 Scenario: Product listing page (like e-commerce) re-renders all items on state change const Product = React.memo(({ item }) => { return <div>{item.name}</div>; }); 🔹 2. Prevent Function Re-Creation in Child Props 👉 Scenario: Passing handlers causing child re-renders const handleClick = useCallback(() => { console.log("Clicked"); }, []); 🔹 3. Expensive Computation Optimization 👉 Scenario: Filtering/sorting large datasets const filteredData = useMemo(() => { return data.filter(item => item.price > 100); }, [data]); 🔹 4. Debouncing API Calls in Search 👉 Scenario: Avoid API call on every keystroke useEffect(() => { const timer = setTimeout(() => { fetchData(query); }, 500); return () => clearTimeout(timer); }, [query]); 🔹 5. Handling Multiple API Calls Efficiently 👉 Scenario: Dashboard with parallel APIs useEffect(() => { Promise.all([api1(), api2()]) .then(([res1, res2]) => { setData({ res1, res2 }); }); }, []); 🔹 6. Code Splitting for Performance 👉 Scenario: Reduce initial bundle size const Dashboard = React.lazy(() => import("./Dashboard")); <Suspense fallback={<div>Loading...</div>}> <Dashboard /> </Suspense> 🔹 7. Prevent Double API Calls (Strict Mode Issue) 👉 Scenario: API hitting twice in development useEffect(() => { let ignore = false; if (!ignore) fetchData(); return () => { ignore = true; }; }, []); 🔹 8. Managing Global State 👉 Scenario: Cart system in e-commerce const cart = useSelector(state => state.cart); const dispatch = useDispatch(); 🔹 9. Handling Forms Efficiently 👉 Scenario: Large dynamic forms const [form, setForm] = useState({}); const handleChange = (e) => { setForm({ ...form, [e.target.name]: e.target.value }); }; 🔹 10. Real-time Updates 👉 Scenario: Live seat booking / notifications useEffect(() => { socket.on("update", data => { setState(data); }); }, []); 💡 Pro Tip: React interviews now focus on: Performance optimization State management decisions Real-world UI scenarios 🔥 If you can explain trade-offs + real use cases, you're already at a senior level. #reactjs #frontenddevelopment #javascript #webdevelopment #interviewquestions #codinginterview #redux #performance #softwareengineering

To view or add a comment, sign in

Explore content categories