Model answers for 4 React questions
Typical round: concepts, then a 30-45 minute component build
Q: What is the difference between props and state? A: Props are inputs passed from a parent and are read-only inside the component. State is data the component owns and updates with a setter, which triggers a re-render. If two siblings need the same data, lift the state to their common parent.
Q: How does useEffect's dependency array work? A: The effect runs after render, then again only when a value in the dependency array changes. An empty array runs it once after mount; no array runs it after every render. Return a cleanup function for subscriptions or timers.
Q: Why do lists need keys? A: Keys let React match list items between renders. Stable, unique keys like IDs keep state attached to the right item; using the array index can cause bugs when items are inserted, removed or reordered.
Q: How do you stop unnecessary re-renders? A: First measure with the React DevTools Profiler. Then keep state close to where it's used, wrap expensive children in React.memo, and stabilise props with useMemo or useCallback only where profiling shows a real cost.